--1列出不及格記錄的學生名單
select distinct student.snum,sname
from sc,student
where sc.snum=student.snum and score<60
--2列出選修了計算機系課程的學生姓名和年齡(表中只有出生年月)
select student.sname,(year(getdate())-year(birthday ))as age
from student
where snum in
(
select sc.snum
from sc,course,[section]
where sc.secnum=[section].secnum and course.cnum=[section].cnum and course.dept='計算機系'
)
--3檢索選修了資料庫技術課程的學生姓名和系別
select student.sname,student.dept
from student
where student.snum in
(
select snum
from sc,[section],course
where sc.secnum=[section].secnum and course.cnum=[section].cnum
and cname='資料庫技術'
)
--4列出選修了所有課程的學生名單
select * from student
where not exists
(
select * from course
where not exists
(
select * from sc,section
where sc.secnum=section.secnum and student.snum=sc.snum
)
)
--5檢索每門課程成績都在80分以上的學生名單
select * from student
where snum in
(
select snum
from sc
group by snum
having min(score)>=80
)
--6檢索獲獎學金的學生 名單(每門課程在80分以上,平均成績在90分以上)
select * from student
where snum in
(
select snum
from sc
group by snum
having min(score)>=80 and avg(score)>=90
)
--7檢索選修了大學英語的學生名單和成績,並按成績從高到低排列
select student.snum,student.sname,sc.score
from sc,student
where student.snum in
(
select snum from sc,section,course
where sc.secnum=section.secnum and course.cnum=section.cnum and cname='大學英語'
)
order by score desc
--8統計每門課程的選修人數,輸出列明為課程號,人數
select cnum as 課程號,count(*) 人數
from section,sc
where section.secnum=sc.secnum
group by cnum
--9查詢選修了資料庫技術,沒有選修高等數學的學生姓名和系別
select student.sname,student.dept
from student
where student.snum in
(
select distinct snum from sc,section,course
where sc.secnum=section.secnum and section.cnum=course.cnum and course.cname='大學英語'
)
and student.snum not in
(
select distinct snum from sc,section,course
where sc.secnum=section.secnum and section.cnum=course.cnum and course.cname='高等數學'
)
--11統計每門課程的選課人數及不及格人數
select cnum,count(*) as 選課人數, case when
(
select count(*) from sc,section
where sc.secnum=section.secnum and score<60
group by cnum
) is NULL then 0 else (
select count(*) from sc,section
where sc.secnum=section.secnum and score<60
group by cnum
) end as 不及格人數
from sc,section
where sc.secnum=section.secnum
group by section.cnum
Ⅱ 使用SQL語句刪除沒有學生選修的課程記錄
1、第一步,創建學生和課程,詳細代碼見下圖,轉到下面的步驟。
Ⅲ 檢索選修大學英語的學生名單和成績,成績高到低排,求改正!
沒仔細看你的CREATE,只看了最後的查詢語句,一眼就可以看出來,你的ORDER BY沒有任何用處。
你可以這樣想,SQL查詢是隨機的,那麼你先排序,然後在外層又SELECT一遍,豈不是排好的數據又被隨機打亂了?所以,ORDER BY一定是最外層的!
Ⅳ 刪除選修了英語課的學生的成績信息sql語言
deletefrom成績表where課程號in(select課程號from課程表where課程名稱='英語')
Ⅳ 資料庫學生信息表如何刪除某個同學的記錄信息
對於資料庫表來說,不會做刪除操作的,這樣其實不太安全,學生信息表應該有一列是狀態,改成無效或退學,然後會有一張記錄這種信息的表,把這個同學的退學日期,原因,經手人等等信息新增上去。
Ⅵ 資料庫中現有學生表,選課表,成績表,怎麼刪除大於18歲學生的所有選課信息
假設這3個表的結構如下:
學生表(學號,姓名,年齡,出生日期)
選課表(學號,課程號,課程名稱)
成績表(學號,課程號,成績)
以上述表結構為前提,T-SQL語句如下:
delete 成績表 where 學號 in (select 學號 from 學生表 where 年齡>18)
delete 選課表 where 學號 in (select 學號 from 學生表 where 年齡>18)
如果學生表中沒有『年齡』欄位,只有『出生日期』欄位的話,T-SQL語句如下:
delete 成績表 where 學號 in (select 學號 from 學生表 where datediff(yy,出生日期,getdate())>18)
delete 選課表 where 學號 in (select 學號 from 學生表 where datediff(yy,出生日期,getdate())>18)
Ⅶ 如何刪除一個資料庫中某個學生的全部記錄
例如你有一個學生表student 你要刪除表格裡面的一個叫劉慧同學的信息
你就應該敲 delete * from student where name = 『劉慧』(方法:delete from <數據表> where 學號='學生的學號')
Ⅷ 資料庫:在選修課中刪除選修了授課班號為'246403'這門課程的學生信息
--樓主既然篩選的是授課班號 那就寫授課班號了
--不明白可以隨時問我 希望採納
--如果你刪除的是關聯的表 也就是說不是此表的話 就得寫個鏈接 或者子查詢也可以
Delete 學生選課表 where 授課班號=『246403』
--如果你刪除的是學生表的內容的話
delete 學生表 where xh in(select xh from 學生選課表 where 授課班號=『246403』)