当前位置:首页 » 编程语言 » sql语句按院系统计人数
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql语句按院系统计人数

发布时间: 2022-07-14 05:38:41

❶ 查询出每个部门的人员总数,sql语句怎么写

sql 使用sum 与 group by
可以统计每个部门的总人数
sum统计总人数 group by根据部门分组
例子
id departmentname number
1 技术 10
2 技术 3
3 销售 50
sql语句
select departmentname ,sum(number)number from table group by departmentname ;
结果
departmentname number
技术 13
销售 50

❷ SQL语句统计各学院人数求解

没给表结构,怎么写??????????????

select "学院",count(*) as "各学院人数" from "表名";

❸ sql语言学生信息表 编写 1.按照学院统计各个学院的人数,结果升序排列,只显示人数超过1000的

1、select 学院 ,count(*) from 学生信息表 group by 学院 having count(*)>=1000 order by count(*)

❹ 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语句 按院系统计学生人数

select 系别,性别,count(*) 人数 from table group by 系别,性别 order by 人数 desc 上面语句不行的话: select * from (select 系别,性别,count(*) 人数 from table group by 系别,性别) order by 人数 desc

❻ 用sql语句统计每个系的男生人数和女生人数,结果按照人数多寡降序。

select 系别,性别,count(*) 人数 from table group by 系别,性别 order by 人数 desc
上面语句不行的话:
select * from (select 系别,性别,count(*) 人数 from table group by 系别,性别) order by 人数 desc

❼ 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语句代码:   A)统计所有学生在各院系的

-----A-------------------------------
SELECT 学院.学院名称, count(*) as 各学院人数FROM 班级, 学生, 院系
WHERE 班级.院系Id = 院系.院系Id
AND 学生.班级Id = 班级.班级Id
GROUP BY 学院.学院名称;
-----B-------------------------------
SELECT 性别, count(*) as 性别对应人数
FROM 学生GROUP BY 性别;

❾ SQL数据库按系部统计课程的平均报名人数,要求显示系部名称、平均报名人数。

1、首先创建一个临时表,用于演示sqlserver语法中的平均值AVG使用。比如,计算一门课程的平均分数。

❿ sql语句统计各部门不同人员类别的人数

第一步,依据你上边给的语句创建一个视图

createviewv_dept
as
selectbd_deptdoc.deptcodeasdeptcode,
bd_deptdoc.deptlevelasdeptlevel,
bd_deptdoc.deptnameasdeptname,
bd_psndoc.psnnameaspsnname,
bd_psncl.psnclassnameaspsnclassname,
bd_psncl.psnclasscodeaspsnclasscode
frombd_psndoc
innerjoinbd_deptdoc
onbd_psndoc.pk_deptdoc=bd_deptdoc.pk_deptdoc
innerjoinbd_psncl
onbd_psndoc.pk_psncl=bd_psncl.pk_psncl

第二步,动态执行sql,由于你人员类别可能不止就3种,所以要动态执行

declare@sqlvarchar(4000)
set@sql='selectdeptcode,deptname'
select@sql=@sql+',sum(isnull(case[psnclassname]when'''+[psnclassname]+'''then1end,0))as
['+[psnclassname]+']'
from(selectdistinct[psnclassname]fromv_dept)asa
select@sql=@sql+'fromv_deptgroupbydeptcode,deptname'
exec(@sql)