sql基础语句

上一篇 / 下一篇  2012-12-07 16:07:35

sql语句
最基础的:
1、查看学生表(st)的全部数据
select * from st
2、向学生表中插入一个学生信息
insert into st(st_name,st_sex,st_age) values ("严芳","女",20)
3、更新一条数据
update st set st_sex="男” where st_name="王芳”
4、删除一条数据
delete from st where st_name=“王芳”
有条件的:
1、查询class_id 大于1的所有信息
select * from class where cl_id>1
2、or
select * from class where cl_id<>1 or cl_class=“大明一班”
3、and
select * from class where cl_id<>1 and cl_class=“大明一班”
4、like 和%
select * from class where cl_class like“大明%”
5、between
select * from class where cl_id between 3 and 5
6、between 配合not
select * from class where cl_id not between 3 and 5
7、is not null
select * from class where cl_remark is not null
8、in
select * from class where cl_cass in(“大明一班”,“小明二班”)
9、count 查询课时数小于50的课程一共有多少门
select count(*) from course where co_num<50
10、sum 查询所有课程一共多少课时
select sum(co_num)from course
11、计算全部课时费,假设每节课50块钱
select sum(co_num)*50 from course
12、查询课时最少的课程
select min(co_num) from course
13、查询课时最多的课程
select max(co_num) from course
14、查询平均每门课多少课时
select avg(co_num) from course
15、 order by  功能 - 排序
select * from studio order by st_name
16、多排序条件
select * from studio order by st_name DESC,st_age DESC,st_sex DESC
17、有条件,主要是看下条件和子句的位置
select * from studio where cl_id=1 order by st_name
18、GROUP BY 子句  功能 - 分组统计
select cl_id as '班级编号',count(*) as '人数' from studio group by cl_id
19、宿舍统计年龄平均值
select ho_id as '宿舍编号',avg(st_age) as '平均年龄' from studio group by ho_id
20、多分组
select ho_id as '宿舍编号',cl_id as '班级编号',avg(st_age) as '平均年龄' from studio group by ho_id,cl_id
21、有条件,主要是看下条件和子句的位置
select ho_id as '宿舍编号',avg(st_age) as '平均年龄' from studio where cl_id=1 group by ho_id
22、

TAG:

 

评分:0

我来说两句

Open Toolbar