SQL第九章資料查詢基礎上機題1 4

2021-07-24 19:41:56 字數 2150 閱讀 5843

//查詢學生相關基本資訊

select * from student where gradeid=1

select studentname,phone from student where gradeid=2

select studentname+phone from student where gradeid=2

select * from student where gradeid=1 and ***='女'

select subjectname from subject where classhour>60

//查詢學生相關複雜資訊

select subjectname from subject where gradeid=1

select studentname,[address] from student where gradeid=2 and ***='男'

select studentname,gradeid from student where email is null

select studentname from student where gradeid=2 and borndate>1990

select studentresult from result where examdate='2013-2-15' and subjectid=1

//使用排序查詢學生相關資訊

select * from student where gradeid=1 order by borndate

select * from result where subjectid=1 order by examdate,studentresult desc

select top 5 studentresult from result where subjectid=8 and examdate='2013-3-22' order by studentresult desc

select top 1 subjectname from subject where gradeid=3 order by classhour desc

select top 1 gradeid,studentname from student order by borndate desc

select top 1 subjectid from result where examdate='2013-3-22' order by studentresult

select * from result where studentno='s1101003' order by examdate

select top 1 studentresult ,subjectid,examdate from result where studentno='s1101003' order by studentresult desc

//使用函式查詢學生相關資訊

elect * from student where gradeid=2 and datediff(yy,borndate,'11/22/2016')>20

select * from student where datename(mm,borndate)=1

select gradeid ,studentname from student where convert(varchar(2),datepart(mm,getdate()))+convert(varchar(2),datepart(dd,getdate()))= convert(varchar(2),datepart(mm,borndate))+convert(varchar(2),datepart(dd,borndate))

select right(email,(len(email)-charindex('@',email,1)))as email網域名稱 from student where studentno='y21003012'

select top 1 's1'+convert(varchar(4),datepart(yyyy,getdate()))+convert(varchar(2),datepart(mm,getdate()))+convert(varchar(2),datepart(dd,getdate()))+right(rand(),4)+'@jbit.com' as 郵件位址 from student

第九章 資料查詢(二)

9.4 連線查詢 9.4.1 內連線查詢 最常見的是相等連線,最後的結果集只包含參加連線的表中與指定字段相符的行。select name,books from tb login,tb book where tb login.user tb book.user 9.4.2 外連線查詢 1.左外連線 t...

SQL基礎第九章行函式

第九章 行函式 行函式會在表單獨某個行的基礎上計算新值這個新值可以基於乙個列中的資料。或者基於幾個不同列中的資料。一些行函式只能用於數字而另一些行函式則可以用於文字或者日期。第二節任務 建立乙個向1 foods表新增乙個新列的新錶,通過使用行函式建立新的列。這個新列將price,price incr...

c 基礎 (第九章)

結構體型別說明 struct 結構體識別符號 成員變數列表 如果沒有結構體識別符號,則稱為無名結構體型別 引用結構體變數成員 l 結構體變數名.成員名 l 結構體指標名 成員名 l 結構體指標名 成員名 共用體共用體所有變數共用一塊記憶體 定義格式如下 union 共用體識別符號 成員變數列表 列舉...