2015-10-27 13:21 GMT+01:00 Rami Ojares <[email protected]>: > > > SELECT > string_agg(title, ', ') > FROM > film > WHERE > title LIKE 'AN%' > HAVING > count(*) > 5 > > > "Return a concatenation of all the films starting with "AN", *IF* there > are at least 5 such films." > > > Where in the statement does it say that the rows should be grouped by > their title column? >
Not grouped by the title column. The title columns are aggregated via a concatenation operation: string_agg() > To be more specific what does GROUP BY() mean? > () is the empty GROUPING SET. The subtle difference between GROUP BY () and no GROUP BY / HAVING at all is the fact that with GROUP BY (), you can get zero rows. Without GROUP BY / HAVING, you will get at least one row. The SQL Server documentation explains this very nicely with examples: https://technet.microsoft.com/en-us/library/bb522495(v=sql.105).aspx GROUPING SETS are a feature that have been introduced to the SQL:1999 standard (https://en.wikipedia.org/wiki/SQL:1999). Special cases of GROUPING SETS are ROLLUP, CUBE, and the empty grouping set. > I would understand the statement better if it would have GROUP BY(title). > But that wouldn't be an equivalent query. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
