sql - Why is a group by clause required when rows are limited in where clause? -
sql - Why is a group by clause required when rows are limited in where clause? -
fiid primary key of table1. why query homecoming many rows there fiid in table1. fiid beingness limited 1 row in clause. query performs when grouping table1.fiid added, certainly should not needed? thanks.
select table1.fiid, sum(case table2.type in (4,7) table2.valuetosum else 0 end), table1 inner bring together table3 on table1.fiid = table3.parentid inner bring together table2 on table2.leid = table3.fiid table1.fiid = 76813 , table2.insid = 431144
when using aggregate functions in select such sum , count when selecting other columns well, group by including additional columns required. while don't know exact reason behind this, helps set results in context.
consider next query:
select name, count(product) numorders customerorders grouping name here, assume results this:
class="lang-none prettyprint-override">name numorders ------------------ joe 15 sally 5 jim 23 now, if sql did not require group by, expect output be? best guess this:
name numorders ------------------ joe 43 sally 43 jim 43 in case, while there may in fact 43 order records in table, including name doesn't provide useful data. instead, have bunch of names out of context.
for more on this, see similar question here: why need explicitly specify columns in sql "group by" clause - why not "group *"?
sql oracle
Comments
Post a Comment