Tag Info

New answers tagged

2

Without table structure, it's not easy to write code but here is a simplified query: SELECT c.*, i.*, r.max_date FROM customer AS c LEFT JOIN -- or just JOIN ( SELECT customernumber, MAX(revenue_date) AS max_date FROM revenue GROUP BY customernumber ) AS r ON ...


1

Note: I replaced recieved with received everywhere. Index First and foremost, for your type of query this is the much better index: CREATE INDEX de_tt_priceinfo_received_station_id_idx ON public.de_tt_priceinfo (station_id, received); -- note the reversed order Since the combination is supposed to be unique (I assume), I suggest a UNIQUE constraint on ...


0

It's a textbook case for a CTE, like @Daniel commented. The example can be simplified some more. And you need to be aware of how LIMIT works in a UNION query. CREATE OR REPLACE FUNCTION featured_products(valid_to_in timestamp , taxonomy_id_in integer , ...


3

Let's pretend for a moment that CTE_RealAudit is a normal table... You're querying it twice! Once to get the list of Minutes values, and to get all the other fields for those rows that have a Minutes value (oh, and surely it always will have, unless you have NULLs) in the list. So yes, that's going to take a lot longer than querying it once. So that's why ...



Top 50 recent answers are included