当前位置:首页 » 编程语言 » sql查询总人数

sql查询总人数

发布时间: 2023-01-14 14:57:32

sql 查询某门课程及格的总人数以及不及格的总人数以及没成绩的人数

1、创建测试表,

create table test_score(class_id varchar2(20), student_id varchar2(20), score number);

㈡ 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 统计人数怎么写,求高手指导

建表:create table student(
sno char(8) not null primary key,
sname varchar(8),
sex char(2) not null CHECK (sex in('男','女')),
age int ,
grade char(8),
deptno char(8))
统计学生总人数:select count(*) from student;
将学生张三从编号001系转为002系:update student set deptno="002" where sname="张三";

㈣ 用T-SQL语句。查询员工总人数

能把员工表结构说出来吗?
比如员工表叫做tbEmployee
select count(*) from tbEmployee就能查出总人数了

㈤ 用T-SQL语句。查询员工总人数

use
库名
select
count(查询的列名)
as
员工总人数
from
员工表名
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查询一个班级中总共有多少人以及男女分别多少人

create view StuClassView as
SELECT s.ID ,s.StuName ,s.StuAge ,s.StuAddress ,s.StuTel ,s.ClassId ,s.StuId,s.StuSex ,e.ClassName,e.ClassInfo,e.ClassFlag
FROM Classes as e left join Students as s on s.ClassId=e.ClassIdselect sc.ClassName as '班级名称',count(sc.StuId) as '总人数' ,sum(case when sc.StuSex='男' then 1 else 0 end) as '男', sum(case when sc.StuSex='女' then 1 else 0 end) as '女' from StuClassView as sc group by sc.ClassName!

㈧ 24.查询学生总人数 用sql语言编写

select count(学号) from 课程信息表 where 课程信息='课程名'

㈨ 查询出每个部门的人员总数,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中怎样查询同一个姓的人数

工具/材料:SQLServerManagementStudio、数据表people。

1、首先在桌面上,点击“SQLServerManagementStudio”图标。

2、然后在该界面中,打开左侧数据表people,显示内部信息。

3、之后在该界面中,点击左上角“新建查询”选项。

4、接着在该界面中,输入sql语句“selectCOUNT(*)frompeoplewherenamelike'李%'”。

5、然后在该界面中,点击左上方“执行”按钮。

6、最后在该界面中,显示同一个姓的人数。

热点内容
邮政登陆密码是什么意思 发布:2025-07-15 01:53:23 浏览:229
算法与程序设计vb 发布:2025-07-15 01:50:39 浏览:719
什么是测试脚本 发布:2025-07-15 01:44:58 浏览:514
商汤科技存储负责人 发布:2025-07-15 01:24:21 浏览:252
文件夹如何批量替换文件名 发布:2025-07-15 01:19:15 浏览:68
ftp上传网页 发布:2025-07-15 01:13:09 浏览:182
音乐文件夹图标 发布:2025-07-15 01:03:41 浏览:495
安卓机怎么反向充电 发布:2025-07-15 01:03:40 浏览:501
电脑使用华为云服务器 发布:2025-07-15 00:48:10 浏览:534
中考应该如何排解压力 发布:2025-07-15 00:17:54 浏览:363