单表查询:
select * from



select sname from stu;

条件查询
select sname from stu where sid=2;

select sname from stu where sid>2;
select sname from stu where sid!=2;
查询时取别名,
select sid as 学号,sname as 姓名 from stu;

模糊查询,
select * from stu where sname like '小%'; % 有多少相似查出多少,

select * from stu where sname like '小_'; _ 有几条线,查出几条,,
select * from stu where sname like '小___'; _ 有几条线,查出几条,,
排序 order by 字段名
select * from stu order by tzid 【asc】; 升

select * from stu order by tzid desc; 降

限制查询 limit
select * from stu limit 3; 可以理解为第 0 条开始往下 3条,

select * from stu limit 3,1 从第 3 条往下第 1 第,

平均值:
select avg(age) from dstu; 求培元年龄,

sql> select round(avg(age)) from dstu; 四舍五入平均值,统计

统计: 有几条数据
select count(age) from dstu;

求最大值
> select MIN(age) from dstu;

求最小值
select MIN(age) from dstu;
求和
select SUM(age) from dstu;
分级查询GROOP BY
统计出现的次数,
select count(*) from stu GROUP BY tzid; 可以看成是查询每个科目的报名人数,

统计每个科目报名人数,
select tzid,count(sid) from stu group by tzid;
科目 学生人数 学生表 科目

分组条件查询,having
select tzid as 科目,count(sid) as 学生人数 from stu group by tzid having 学生人数=2;

多表查询 (着想查询)
select * from dstu where age > 19.5;

子查询:
一条语句结合两条语句,
select * from dstu where age > (select avg(age) from dstu);
着想查询:
内连接 [INNER| CROSS] JOIN
同时查询二个表,
select * from tanzhou,stu;

select * from stu inner join tanzhou;

关联查询:
select * from stu inner join tanzhou on tzid=sid;

外连接 { LEFT| RIGHT } JOIN
select * from stu left join dstu on id = sid;

与内连接相比,可以显示所有学生,包括未选课的学生,
作业;:
查询学生详情表性别为男,并年龄大于18,
select * from dstu where age>18 and sex='b';

在此基础上查改名,..

需求: 作为宿管,想知道学生的 ( 姓名, 年龄,性别,所属学

select name js from 表单名 where js between 70 and 90 ;
找出分数在70到90的。