select sClass 班级,count(*) 班级学生总人数, sum(case when sGender=0 then 1 else 0 end) 女生人数, sum(case when sGender=0 then 1 else 0 end)*1.0/count(*)女生所占比例, sum(case when sGender=1 then 1 else 0 end) 男生人数, sum(case when sGender=1 then 1 else 0 end)*1.0 /coun
创建表:Create table If Not Exists Employee (Id int, Name varchar(255), Salary int, DepartmentId int);Create table If Not Exists Department (Id int, Name varchar(255));Truncate table Employee;insert into Employee (Id, Name, Salary,DepartmentId) values ('
1.复杂SQL查询 1.1.单表查询 (1)选择指定的列 [例]查询全体学生的学号和姓名 select Sno as 学号,Sname as 姓名 from student; select Sno,Sname from student; (2)查询全部列 [例]查询全体学生的详细信息 select * from student; (3)对查询后的指定列进行命名 [例]查询全部学生的“姓名”及其“出生年”两列 select Sname as 姓名,(2014-Sage) as 出生年 from s
select 一.课上练习代码 1 查询所有学生信息 select * from tb_student; select * from tb_teacher; 2 查询所有课程名称及学分(投影和别名) select couname, coucredit from tb_course; select couname as 课程名称, coucredit 学分 from tb_course; select stuname 姓名, case stusex when 1 then '男' else '女'
基本SQL查询语句以及函数的使用 格式元素 描述 YYYY 四位的年份 MONTH 月份的英文全称 MON 月份的英文简写 MM 月份的数字表示 DD 日起的1-31数字表示 D 星期几的数字表示1-7 DAY 星期几的全称 DY 星期几的英文简写 HH,HH24 时的数字表示1-12,1-24 MI 分 SS 秒 IW 本年过去的周数 --说明:查询基于HR用户表 --判断条件的综合可以使用AND OR --1.查询EMPLOYEES表的所有内容 SELECT * FROM HR.EMPLOY
如何用一个SQL查询出一个班级各个学科第N名是谁? 首先贴出建表语句,方便大家本地测试: -- 建表语句 CREATE TABLE score ( id INT NOT NULL auto_increment, `name` VARCHAR (20) NOT NULL DEFAULT '' COMMENT '姓名', sub VARCHAR (20) NOT NULL DEFAULT '' COMMENT '学科', score INT NOT NULL DEFAULT 0 COMMENT '分
--SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 end),null),null) as NotNullCountfrom syscolumns aINNER JOIN( select [id], [name] from [sysobjects] where [type] = 'u' ) AS b ON a.id = b.[id] GROUP b
1秒查原本递归的查询. 适用于:上下级.多层查询 -- Get childs by parent id WITH Tree AS ( SELECT Id,ParentId FROM dbo.Node P WHERE P.Id = -- parent id UNION ALL SELECT C.Id,C.ParentId FROM dbo.Node C INNER JOIN Tree T ON C.ParentId = T.Id ) SELECT * FROM Tree -- Get parent