欢迎光临
我们一直在努力

数据库系统原理与设计——投影运算、选择运算

书籍:数据库系统原理与设计(第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 

*/

该教材相关资料请点击如下链接:

https://blog.51cto.com/sky9896/2323447

http://down.51cto.com/data/2456174

实战技巧:完成一个任务,可以使用两种方法来完成。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。