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
$get_sql = "SELECT sql_calc_found_rows field1,field2 FROM table WHERE name = '1' order by add_time desc limit 2,20 "; $get_total_sql = "SELECT FOUND_ROWS() as total";
select * from student select * from score --select * from grade select * from course select * from teacher --1. 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from Student --2. 查询教师所有的单位即不重复的Depart列. select distinct depart from teacher -
step1:在mysql cmd中新建存储过程: drop procedure if exists queryCountByGrade ; delimiter // -- 定义存储过程结束符号为// create procedure queryCountByGrade(IN gradenameinput INT(),OUT counts ) begin select count(*) into counts from student where grade = gradenameinput;en
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