當前位置:首頁 » 編程語言 » sql語言怎麼看已婚人數
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql語言怎麼看已婚人數

發布時間: 2022-10-30 09:38:30

sql語言怎麼查詢未婚的人

看看記錄中有沒有表示婚否的欄位,加上where條件判斷欄位就好了。

❷ 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

❹ 如何用一條SQL語句查詢出男女個數和已婚個數

select sum(case xb = '男' when 1 else 0 ) as "男人的個數"
sum(case xb= '女' when 1 else 0 ) as "女人"
sum(case yh = '是' when 1 else 0 ) as "已婚個數" from biao

❺ 在sql中怎樣查詢同一個姓的人數

工具/材料:SQL Server Management Studio、數據表people。

1、首先在桌面上,點擊「SQL Server Management Studio」圖標。

❻ 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
分別查詢上述五門科目各科的學生名字,返回結果為(科目,學該科目的學生名字)

❼ sql 查詢每個年齡的人數

select COUNT(*) as 每個年齡的人數,年齡 from 員工表 group by 年齡

❽ 用SQL語句怎麼統計人數

select sum(case when 研究生性別=『男' then 1 else 0 end) / sum(case when 研究生性別=『女' then 1 else 0 end) from tab 和求出了怎麼比

❾ 如何用SQL命令在已知表中查詢所有已婚的,記錄的職工號、姓名,性別,和出生日期,結果按姓名升序排序

select 職工號,姓名,性別,出生日期 from 表名 where 婚否='已婚' order by 姓名 asc
不過默認就是升序

❿ 復雜的SQL 語句

select 職工號,姓名,性別,出生日期 into infor_da from 表 where 婚姻狀況='已婚' order by 出生日期 desc

exec master..xp_cmdshell 'bcp 資料庫名..infor_da out c:\ma_da.txt -c -t'

也可以這樣,直接導出結果,不用放入臨時表

exec master..xp_cmdshell 'bcp "select 職工號,姓名,性別,出生日期 into infor_da from 資料庫名..表 where 婚姻狀況=''已婚'' order by 出生日期 desc" queryout c:\ma_da.txt -c -t'

樓上的方式太不前衛了,還需要開始,運行,輸入cmd,用我的方式一勞永逸