当前位置:首页 » 编程语言 » 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,用我的方式一劳永逸