Re: Combining two SELECTs
| От | Guillaume Perréal | 
|---|---|
| Тема | Re: Combining two SELECTs | 
| Дата | |
| Msg-id | 3962E550.B685F556@lyon.cemagref.fr обсуждение исходный текст | 
| Ответ на | Combining two SELECTs ("Eric Jain" <jain@gmx.net>) | 
| Список | pgsql-general | 
Tom Lane wrote: > > "Eric Jain" <jain@gmx.net> writes: > > Any ideas how the following two statements could be combined into a > > single one? > > > SELECT DISTINCT host, url, id > > INTO TEMP > > FROM log > > WHERE > > host IN (SELECT host FROM robots) > > AND status IN (200, 304); > > > SELECT host, COUNT(*) AS hits > > FROM TEMP > > GROUP BY host > > ORDER BY hits DESC; > > Offhand I do not think you can do this in one "simple" SQL query, > because the SQL query semantics require that GROUP BY grouping occurs > before DISTINCT processing, whereas you want the other order. > > > For now, the temp table seems like a good workaround. > And splitting some complex queries in simpler ones (using temp tables) can increase performance, depending on the query. Regards, Guillaume Perréal - Stagiaire MIAG Cemagref (URH), Lyon, France Tél: (+33) 4.72.20.87.64
В списке pgsql-general по дате отправления: