1. sql 數據管理與實現,(1)查詢所有男同學的信息。 (2)查詢有不及格課程的學生信息及不及格課程的名稱和成績
1,select * from 學生 where 性別='男'2.sekect * from 學生,成績表 where 學生.學號=成績表.學號 and 成績表.成績<603.create trigger tri_學生_delete on 學生 instead of delete as begin if exists(select * from 成績表 where 學號 in (select 學號 from deleted)) print '成績表中有該記錄對應的學生的成績'; else delete from 學生 where 學號 in (select 學號 from deleted) end2. SQL語句求助:統計各班每門課程成績均不及格的同學人數
select
a.score
,count
as
人數
,col2
as
科目
from
(select
case
when
col1>=60
then
'及格'
else
'不及格'
end
as
score
,col2
from
tb
g
)
a
group
by
a.score,a.col2
3. SQL語句求助:統計各班每門課程成績均不及格的同學人數
根據題目要求,簡單分析可以知道,其實這條查詢語句只使用「學生選課」和「學生」這兩張表即可。此處應該使用「左連接」,用學生表中的班級欄位進行「分組」,用COUNT()函數對分數小於60的同學的個數進行統計。
SELECT 學生.班級,COUNT(學生選課.成績<60)
FROM 學生選課
LEFT JOIN 學生
ON 學生選課.學生ID=學生.學生ID
GROUP BY 學生.班級
你可以進行驗證一下,如果不對,或者有更優化的方法,可以相互學習!
4. SQL查詢出有成績不及格的學生的學號,姓名,課程名。
select a.學號 , a.姓名 , b.課程名
from tbStudent a , tbCourse b , tbScore c
where c.成績 < 60 and a.學號 = c.學號 and b.課程號 = c.課程號
5. 成績表裡有多門課程,查詢成績比該課程平均分低的同學的信息 sql語句查詢
select 成績,avg(成績)having 成績<avg(成績)group by 成績
6. 排錯SQL:列出有二門以上(含兩門)不及格課程的學生姓名及其平均成績
因為你按照s.sname分了組並且用了聚集函數avg(sc.scgrade),就必須用group by按照s.sname分組才行啊,如果select中沒有s.sname,只有聚集函數avg(sc.scgrade)的話肯定就是對的,但是不符合你題目的要求了。下面這個就是對的了,因為除了聚集函數的選擇項都被分組了,在上面那個後面加上group by s.sname應該就對了,不過不知道sname是不是唯一鍵。
唉,也不知道自己說清楚沒,不清楚的可以發信問我。
7. SQL資料庫的問題目
這是在一個student資料庫上建立的查詢,你可以把郵箱告訴我,我把資料庫文件發給你,當然如果你想自己建的話也行,下面是三張表。
sno sname ssex sage sdept
200215121 李勇 男 20 CS
200215122 劉晨 女 19 CS
200215123 王敏 女 18 MA
200215125 張立 男 19 IS
cno cname cpno ccredit
1 資料庫 5 4
2 數學 NULL 2
3 信息系統 1 4
4 操作系統 6 3
5 數據結構 7 4
6 數據處理 NULL 2
7 PASCAL語言 6 4
sno cno grade
200215121 1 92
200215121 2 85
200215121 3 88
200215122 2 90
200215122 3 80
--1.查詢所有年齡在20歲以下的學生姓名及其年齡。
select sname,sage
from student
where sage<20
--2.查詢考試成績有不及格的學生的學號。
select sno
from sc
where grade<60
--3.查詢年齡不在19~22歲之間的學生姓名、系別和年齡。
select sname,sdept,sage
from student
where sage not between 19 and 22
--4.查詢既不是信息系,也不是計算機科學系的學生的姓名和性別。
select sname,ssex
from student
where sdept not in ('IS','CS')
--5.查詢所有姓劉學生的姓名、學號和性別
select sname,sno,ssex
from student
where sname like '劉%'
--6.在Course數據表中添加記錄('8','DB_design','2',4),並查詢以"DB_"開頭,且倒數第3個字元為 i的課程的詳細情況
select *
from course
where cname like 'DB\_%i__%' escape'\'
--7.在SC數據表中添加記錄('200215123','1',null),並查詢所有有成績的學生學號和課程號
select sno,cno
from sc
--8.查詢全體學生情況,查詢結果按所在系的系號降序排列,同一系中的學生按年齡升序
select *
from student
order by sdept desc,sage asc
--9.計算2號課程的學生平均成績。
select AVG(grade)
from sc
where cno='2'
--10在SC數據表中添加記錄('200215123','1',23),統計出不及格的同學學號和不及格的門數。
select student.sno,count(grade)
from sc,student
group by student.sno
having grade<60
--11.查詢選修1號課程的學生最高分數。
select MAX(grade)
from sc
where cno='1'
--12.查詢學生200215121選修課程的總學分數。
select SUM(grade)
from sc
where sno='200215121'
--13.求各個課程號及相應的選課人數
select cno,COUNT(sno)
from sc
group by cno
--14.查詢選修了2門以上(包括2門)課程的學生學號
select sno
from sc
group by sno
having count(*)>=2
--15.查詢成績大於等於90分的學生的學號和姓名
select student.sno,sname
from student,sc
where grade>90
--16.查詢選修了「資料庫」課程的學生的學號和姓名
select student.sno,sname
from student inner join sc on student.sno=sc.sno
where cno=(select cno from course where cname='資料庫')
--17.查詢選修了3號課程且成績高於此課程平均成績的學號和成績
select student.sno,grade
from student inner join sc on student.sno=sc.sno
where cno='3'
and grade>(select AVG(grade) from sc)
--18.查詢沒有選修1號課程的學生姓名。
select sname
from student,sc
where cno!='1'
--1.建立計算機系選修了2號課程的學生視圖V1
create view v1
as
select sno,sname,ssex,sage,sdept
from student,course
where sdept='cs' and cno='2'
--2.建立信息系選修了1號課程且成績在90分以上的學生的視圖V2
create view v2
as
select student.sno,sname,ssex,sage,sdept
from student,course,sc
where course.cno='2' and grade>90
--3.將每門課程的課程號和平均成績定義為一個視圖V3
create view v3(cno,avg_grade)
as
select cno,avg(grade)
from sc
group by cno
--三、創建和執行下列存儲過程:
--o 創建語句格式:
--n CREATE Proc[ere] 存儲過程名
--[{@參數名 數據類型}[=default][output]]
--As
--Sql語句[…n]
--o 執行語句格式:
--n [exec[ute]] 存儲過程名[實參[,output][,…n]
--1.查詢計算機系學生的考試成績,列出學生的姓名、課程名和成績。
select sname,cno,grade
from student,sc
where sdept='cs'
--2.查詢某個指定系學生的考試成績,列出學生的姓名、所在系、課程名和成績。
select sname,sdept,cname,grade
from student,sc,course
where sdept='%'
--3.查詢某個學生某門課程的考試成績,列出學生的姓名、課程名和成績。
select sname,cno,grade
from student,sc
where sname='%' and cname='%'
--4.查詢某個學生某門課程的考試成績,若沒有指定課程,則默認課程為「資料庫基礎」。
select sname,cno,grade
from student,sc
where sname='%' and cname='%'
--5.統計指定課程的平均成績,並將統計的結果用輸出參數返回。
--6.創建帶刪除數據的存儲過程,要求刪除考試成績不及格學生的修課記錄。
--7.創建帶修改數據的存儲過程,要求將指定的課程的學分增加2分。
8. SQL統計每門課程的不及格人數
你的要求有點特別,要求 學號!
如果只是
統計每門課程的不及格人數下面的SQL就可以啦:
select cnum,count(cnum) as 不及格人數
from sc
where score < 60
group by cnum 注意:是對課程號分組喲,樓上的是錯的。
如果你要輸出學號:
Select sc.snum as 學號,
a.cnum as 課程號,
a.不及格人數
From sc,
(select cnum,count(cnum) as 不及格人數
from sc
where score < 60
group by cnum) as a
where sc.score<60 and sc.cnum=a.cnum
以上我相信是沒有問題的,你測試一下!
如果OK,給分喲
呵呵
9. 查詢信息系三門以上不及格課程的學生學號和姓名 用sql語句怎麼寫
請參閱以下sql
select[學號],[姓名]from[學生信息表]whereexists(
(select[學號]from[成績表]where[課程]<60
groupby[學號]havingcount([課程])>=3)ast1
where[t1].[學號]=[學生信息表].[學號]
)
有疑問及時溝通
一般情況下,這樣寫就可以了
請採納!