GROUP BY & HAVING 用法

显示每个地区的总人口数和总面积.
SELECT region, SUM(population), SUM(area) FROM bbc GROUP BY region

显示每个地区的总人口数和总面积.仅显示那些面积超过1000000的地区。
SELECT region, SUM(population), SUM(area) FROM bbc GROUP BY region HAVING SUM(area)>1000000

select count(*),sum(t.tranamt),t.termid from wt_pep_jnls t where t.tranamt > 0 group by  t.termid order by sum(t.tranamt) desc

SELECT store_name, SUM(Sales) FROM Store_Information GROUP BY store_name

你可能感兴趣的:(group by)