1. 程式人生 > >資料庫系統原理與設計——投影運算、選擇運算

資料庫系統原理與設計——投影運算、選擇運算

書籍:資料庫系統原理與設計(第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

實戰技巧:完成一個任務,可以使用兩種方法來完成。