第四章高階查詢

2021-07-25 23:00:17 字數 2924 閱讀 8904

--案例1:檢查「oop」課程最近一次考試。--如果有80分以上的成績,則每人提2分;

--否則,每人提5分。最終的成績不得大於100分

if exists

( select studentresult from result

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max(examdate) from result

where subjectid=

( select subjectid from subject

where subjectname='oop'

) )

and studentresult>80

) begin

--有,每人提2分 99

update result set studentresult=100

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max(examdate) from result

where subjectid=

( select subjectid from subject

where subjectname='oop'

) )

and studentresult>98

update result set studentresult+=2

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max(examdate) from result

where subjectid=

( select subjectid from subject

where subjectname='oop'

) )

and studentresult<=98

endelse

begin

--沒有,整體+5

update result set studentresult+=5

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max(examdate) from result

where subjectid=

( select subjectid from subject

where subjectname='oop'

) )

endselect * from result

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max(examdate) from result

where subjectid=

( select subjectid from subject

where subjectname='oop'

) )

---分頁:雙top 雙order by  每頁顯示3條記錄,我想要第二頁資料 4-6條

select top 3 * from student

where studentno not in

( select top 0 studentno from student

)

select *from student

子查詢select *from student

where birthday >(select birthday from student where studentno='23311')

--最高分 最低分

select max (studentresult),min(studentresult)from result

where examdate=

(select max (examdate) from result where subjectid =

(select subjectid from subject where subjectname ='oop'))

and subjectid=

(select subjectid from subject where subjectname ='oop'

)--查詢參加'oop'課程最近一次的在讀學生名單(學生姓名,學生編號)

select studentname,studentno

from student

where studentno in

(select studentno from result

where subjectid=

(select subjectid from subject

where subjectname='oop'

)and examdate=

(select max (examdate) from result

where subjectid=

(select subjectid from subject

where subjectname='oop'))

)

第四章 多表查詢

例如 按照department id查詢employee 員工表 和department 部門表 的資訊。方法一 通用型 select from where select e.last name,e.department id,d.department name from employee e,de...

第四章 指標 Pointer(高階)

第四章 指標 pointer 高階 希望初學者在入門的時候,可以看一些英文的原著,我感覺英文書籍是原意,而一些現在中文的翻譯是加上了譯者的一些理解,多少是拿來的東西,所以一些東西我希望能夠按照自己的來。a 就是取存放a的位置,我們可以將這個位置複製給pointer variable。a 從a所指的位...

第四章高階命令2

4.2.3 du 評估檔案大小利用率 du將1024位元組為單位顯示當前目錄的大小 du a 遞迴顯示目錄及目錄下的檔案大小 du h 以易讀形式顯示大小 4.2.4 cron crontab 執行計畫任務 守護程序是cron 命令 crontab etc init.d 目錄池 var spool ...