mysql 常用的聚合函数_mysql 常用聚合函数

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 GROUP BY countrycode;

SELECT district,SUM(Population) FROM city WHERE countrycode='chn' GROUP BY district HAVING SUM(Population) < 1000000 ;

where|group|having

SELECT district,SUM(Population) FROM city WHERE countrycode='chn' GROUP BY district HAVING SUM(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 district

HAVING 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;

标签:city,聚合,函数,countrycode,SUM,district,mysql,GROUP,SELECT

来源: https://www.cnblogs.com/neoo9901/p/14148446.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值