A. 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
分别查询上述五门科目各科的学生名字,返回结果为(科目,学该科目的学生名字)
B. 使用SQL查询,统计每门课程的学生选修人数
ORDER BY 2,是你在用SELECT作查询时,用第二个字段进行排序,
例如 select name,age from 表 order by 2,(指按age字段排序)
select name,age,score from 表 order by 3(指按score字段排序)
C. SQL统计各专业学生人数
CREATE VIEW VIEW1
AS
SELECT 专业表.专业名称, COUNT(学生表.学生ID) AS 人数
FROM 学生表
LEFT JOIN 专业表 ON 专业表.专业ID = 学生表.专业
GROUP BY 专业表.专业ID,专业表.专业名称
D. 如何用SQL语句 按院系统计学生人数
select 系别,性别,count(*) 人数 from table group by 系别,性别 order by 人数 desc 上面语句不行的话: select * from (select 系别,性别,count(*) 人数 from table group by 系别,性别) order by 人数 desc
E. 请写出SQL查询统计每门课程的选修人数显示课程编号学生人数。
SQL查询语句:Select 课程编号,count(*) 学生人数From 课程 group by 选修人数;
PS:SQL用于统计和分组的函数是:
统计函数:count(*)。
分组函数:Group By 分组表达式。
F. sql语句 查询某人数 怎么 查询某个专业学生人数。 在线等 谢啦
select count(*) from 学生表 where 专业 in ('计算机',英语',‘化工') 专业由查询的题目来决定
G. 统计学生(xx)表中使用sql命令用来查询每各专业的男、女生人数
用group by
示例SQL
select 专业, 性别, count(1) from table group by 专业, 性别
祝好运,望采纳
H. 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)