資料庫事務併發帶來的問題
阿新 • • 發佈:2020-12-17
max() :最大值
min() :最小值
avg() :平均值
sum() :總和
count() :個數
group_concat() : 列轉行
SELECT countrycode ,SUM(population) FROM city GROUP BY countrycode; SELECT district,SUM(Population) FROM city WHERE countrycode='chn' GROUP BY district; SELECT countrycode,COUNT(id) FROM city GROUPBY countrycode; SELECT district,SUM(Population) FROM city WHERE countrycode='chn' GROUP BY district HAVING SUM(Population) < 1000000 ;
having :指定一組行或聚合的過濾條件
order by + limit :實現先排序,by後新增條件列
where|group|having SELECT district,SUM(Population) FROM city WHERE countrycode='chn' GROUP BY district HAVINGSUM(Population) < 1000000 ; SELECT * FROM city WHERE countrycode='CHN' ORDER BY population DESC; SELECT district AS 省 ,SUM(Population) AS 總人口 FROM city WHERE countrycode='chn' GROUP BY district ORDER BY 總人口 DESC ; SELECT district, SUM(population) FROM city WHERE countrycode='CHN' GROUP BY districtHAVING SUM(population)>5000000 ORDER BY SUM(population) DESC LIMIT 3 ; LIMIT N ,M --->跳過N,顯示一共M行 LIMIT 5,5 SELECT district, SUM(population) FROM city WHERE countrycode='CHN' GROUP BY district HAVING SUM(population)>5000000 ORDER BY SUM(population) DESC LIMIT 5,5;