1、查看学生的姓氏情况
select distinct substring(name,1,1) from stu
2、运行多个查询语句
注意:go此时可以省略
select * from stu
go
select * from grade
go
3、选取集合数据
select * from stu where name in ('黎明','刘英')
4、识别空值
select * from stu where name is not null
5、匹配符
select name from stu where name like '刘X%' escape 'X'
6、虚拟列
select name as '姓名',round(height*100,1,0) as '身高','CM' as '单位' from stu
7、注释
/*
这是注释
这是注释
*/
select * from stu--这是注释
8、日期函数处理
select year(birthday),month(birthday),day(birthday) from stu where birthday='1976-07-01'
9、暂存表
select * into tempstu from stu
10、多表查询
select name ,cid,grade from stu,grade where stu.number=grade.number
select name ,cid,grade from stu inner join grade on stu.number=grade.number
select name ,cid,grade from stu left outer join grade on stu.number=grade.number
查询谁没有选修课程
select name from stu left outer join grade on stu.number=grade.number where cid is null
11、查询每个人的最小成绩
select name ,min(grade) from stu,grade where stu.number=grade.number group by stu.name
利用“与主查询有关的子查询”
select name,grade from stu ,grade where stu.number=grade.number
and
grade=(select min(grade) from grade where grade.number=stu.number)
[此贴子已经被作者于2006-3-27 21:07:45编辑过]