SQL Server 数据库的统计查询
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/shiyangkai/article/details/71642184
基礎(chǔ)數(shù)據(jù)庫表Table為:
?
?
?
查詢Table表中某個字段的最大值,最小值,平均數(shù)等等。
select MAX(Age) AS 最大年齡,min(Age) AS 最小年齡,avg(Age) AS 平均年齡 from Table
查詢結(jié)果:
?
?
?
使用 group by 統(tǒng)計查詢(男/女)的數(shù)量
select Sex AS 性別,COUNT(*) AS 人數(shù) from Table1 group by Sex
查詢結(jié)果:
?
?
使用 group by 統(tǒng)計查詢也可以查詢多個字段(性別和地址)
select Adderss AS 所在地,Sex AS 性別,COUNT(*) AS 人數(shù) from Table group by Sex,Adderss
查詢結(jié)果:
?
?
?
使用 having 條件統(tǒng)計查詢?nèi)藬?shù)大于2人的地方
select Adderss AS 地址,COUNT(*) AS 人數(shù) from Table group by Adderss having COUNT(*)>=2
查詢結(jié)果:
?
?
---------------------
作者:小哥丷
來源:CSDN
原文:https://blog.csdn.net/shiyangkai/article/details/71642184?utm_source=copy
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!
轉(zhuǎn)載于:https://www.cnblogs.com/lemonote/p/9799253.html
總結(jié)
以上是生活随笔為你收集整理的SQL Server 数据库的统计查询的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 猫:君主般的眼神 监视领地。 狗
- 下一篇: 数据库事务处理差异:可提交读和重复读区别