书籍:数据库系统原理与设计(第3版)——万常选 廖国琼等编著
数据库版本:SQL Server 2005
/*
select courseNO as 课程号,lower(coursename) 课程名,courseHour/16 as 周课时
from course
*/
/* --”%任意字符","_"通配符的使用
select *
from class
where className like '%会计%'
select studentNo,studentName
from Student
where studentName like '王__'
select studentNo,studentName
from Student
where studentName not like '%福%'
select studentNo,studentName,nation
from Student
where nation not like '蒙古族'
select studentNo,studentName,nation
from Student
where nation like '蒙古族'
*/
--通配符的使用
/*
select className
from class
where className like '%16\_%' ESCAPE '\'
union
select className
from class
where className like '%16\_%' --不对
union
select className
from class
where className like '%16_%' ESCAPE '\' --不对
*/
--转义字符的使用,以下两种方法相似
/*
select className
from class
where className like '%16#_%' escape '#'
select className
from class
where className like '%16\_%' ESCAPE '\'
*/
/* --学会逻辑运算符or and
select studentNo,courseNO,score
from score
where courseNo='001' or courseNo='005' or courseNo='003'
select studentNo,courseNO,score
from score
where courseNo='001' and courseNo='003'
select studentNo,courseNO,score
from score
where courseNo in('001','005','003')
*/
/*
select studentNO as 学号,studentName as 姓名 ,year(birthday) as 出生年份
from Student
where year(birthday)=1998 and nation='汉族'
*/
/* --籍贯不在南昌和上海的,两种实施方法,二选一
select studentNO as 学号,studentName as 姓名 ,native
from Student
where native not in ('南昌','上海')
select studentNO as 学号,studentName as 姓名 ,native
from Student
where native!='南昌' and native!='上海'
*/
/* 80——90区间的分数
select studentNo,courseNO,score
from score
where score>=80 and score<=90
select studentNo,courseNO,score
from score
where score between 80 and 90
*/
/*
select studentNo,courseNO,score
from score
where score<80 or score>90
*/
/*
--按籍贯排序
select studentName,native,classNo
from student
where native!='南昌' and native!='上海'
order by native desc
*/
该教材相关资料请点击如下链接:
http://blog.51cto.com/sky9896/2323447
http://down.51cto.com/data/2456174
实战技巧:完成一个任务,可以使用两种方法来完成。