How to make use of WITH in PostgreSQL to reduce query cost
0
I am trying to get twitter data of narendramodi using below command. SELECT b.t_id,a.profile_image,b.tweet_text,e.media_media_url,b.retweet_count,b.favorite_count as like_count,count(reply_to_status_id) as reply_count,f.imp_count,f.eng_count,f.eng_rate FROM twitter_users a LEFT JOIN twitter_tweets b on a.user_id=b.user_id LEFT JOIN replies c on b.t_id = c.t_id LEFT JOIN media e on b.t_id = e.t_id LEFT JOIN metric_aggregates f on f.metric_timestamp= (select max(metric_timestamp) FROM twitter_tweet_metric_aggregates g WHERE g.t_id=f.t_id and g.t_id=b.t_id) WHERE a.twitter_screen_name= 'narendramodi' GROUP BY b.t_id,a.profile_image ,b.tweet_text,b.retweet_count,b.favorite_count, e.media_media_url,f.imp_count,f.eng_count,f.eng_rate); Query was working correctly But, in the above query I have u