『壹』 sql查詢統計某表的男女各個人數
select s.sex,count(s.sex) from student s GROUP BY sex;
GROUP BY 語句
GROUP BY 語句用於結合合計函數,根據一個或多個列對結果集進行分組。
測試student表紀錄如下圖,根據自己需求增刪欄位。
student s ,s是自己為student表定義的別名,count()為統計的人數。
拓展資料:
SQL GROUP BY 語法:
SELECT column_name(列名), aggregate_function(column_name) (函數名) FROM table_name(表名) WHERE column_name operator value GROUP BY column_name
『貳』 利用SQL語句統計出各年齡段人數
select '25-30歲' as 年齡段 count(*) as 人數 from tb where year(getdate())-year(birthday)>=25 and year(getdate())-year(birthday)<30
union all
select '30-35歲' as 年齡段 count(*) as 人數 from tb where year(getdate())-year(birthday)>=30 and year(getdate())-year(birthday)<35
union all
select '35-40歲' as 年齡段 count(*) as 人數 from tb where year(getdate())-year(birthday)>=35 and year(getdate())-year(birthday)<40
『叄』 MY SQL分組查詢每個地方每個狀態的學生人數
這個用case when語句即可實現上述功能,經過測試已全部通過
select location,count(case when status=1 then status end)as '1',count(case when status=2 then status end)as '2',count(case when status=3 then status end)as '3',count(case when status=4 then status end)as '4' from student group by location
『肆』 sql查詢每個單位多少人,包含單位編碼、單位名稱、人數、按單位編碼排序
select 單位編碼,單位名稱,count(1) as 人數 from 表 group by 單位編碼,單位名稱 order by 單位編碼;
沒有提供表結構,我就這么大致表述一下。
如果有幫助到你,請點擊採納。
『伍』 SQL命令統計各姓氏人數
SELECT Left(表名.[姓名], 1) as 家姓,count(Left(表名.[姓名], 1)) as 人數 FROM [表名] group by Left(表名.[姓名], 1);
『陸』 sql 統計人數
select count(stu_id) from student where subject in{『英語』,『政治』,『數學』,『計算機』,『C語言編程'}
上述SQL語句為查詢科目為這五門課的學生總數,如果用count(*),可能沒有剔除重復記錄,所以用count(stu_id)
select subject, count(stu_id) from student where subject in{『英語』,『政治』,『數學』,『計算機』,『C語言編程'} group by subject
分別查詢上述五門科目,每門科目的學生總數,返回的是這樣的數據對(pair):(英語,50) (政治, 45)……
select distinct name from student where subject in{『英語』,『政治』,『數學』,『計算機』,『C語言編程'}
查詢選擇上述五門課的所有學生名字,必須加上關鍵詞distinct,以除去重復的名字(比如同一個學生可以同時選上述五門課)
select subject, distinct name from student where subject in {『英語』,『政治』,『數學』,『計算機』,『C語言編程'}group by subject
分別查詢上述五門科目各科的學生名字,返回結果為(科目,學該科目的學生名字)
『柒』 mrsql如何字元串截取前三位並且統計各省人數
sql中在where字句里截取字元方法如下:
1、如果是sqlserver:where left(p.end_time,4) = '2012'。
2、如果是Oracle:where substr(p.end_time,0,4) = '2012'。
舉例:
1、oracle: 'where substr(欄位名,1,2)='''123''''
2、sqlserver: 'where substring(欄位名,1,2)='''123''''
『捌』 SQL語句查詢:如何查詢各個學院的學院名稱和所在的教師人數、學生人數
SQL語句查詢:查詢各個學院的學院名稱和所在的教師人數、學生人數,使用mysql語句的查詢語句是select count(teacherName) count(studentName) from College group by college。
SQL簡介
SQL 是具有數據操縱和數據定義等多種功能的資料庫語言,這種語言具有交互性特點,能為用戶提供極大的便利,資料庫管理系統應充分利用SQL語言提高計算機應用系統的工作質量與效率。
SQL Server資料庫包括Microsoft SQL Server以及Sybase SQL Server兩個子資料庫,該資料庫能否正常運行直接關系著整個計算機系統的運行安全。
『玖』 SQl統計地區人數該怎麼做
可以用GROUP BY 加CASE WHEN
SELECTCASEWHENaddress='江蘇南京'THEN'南京'ELSEaddressENDASaddressas地區,COUNT(no)人數
FROMtable
GROUPBYCASEWHENaddress='江蘇南京'THEN'南京'ELSEaddressEND
『拾』 現有表學生信息(xsxx),內有欄位省市(ss),怎樣用sql語句統計各省的人數要求輸出欄位為ss,人數!急急急~
select ss,count(*) from xsxx group by ss
輸出的第一個欄位是ss,第二個欄位是各個省市的學生人數