1. sql語句科目表學生表和成績表的查詢
每科的總成績?查詢它干什麼?要查的話這樣查:
SELECT 科目表.KUMUID,KUMUName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 科目表,成績表
WHERE 科目表.KUMUID=成績表.KUMUID
GROUP BY 科目表.KUMUID,KUMUName
由於是查每科的總成績和平均分,所以和學生沒有關系,不用關聯學生表
----------------------------------------------------------------
不過我懷疑你是不是想查每個學生的總成績和平均分,是這樣查的:
SELECT 學生表.UID,UName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 學生表,成績表
WHERE 學生表.UID=成績表.UID
GROUP BY UID,UName
=========================================================
對於樓主的補充的回答:
你所要的SQL語句我已經寫了,這個查詢由於是查詢每個科目的總成績,所以不需要查詢學生的姓名,所以不應關聯學生表。只需要用成績表關聯科目表(目的是查詢出科目的名稱)。然後直接使用分組匯總(就是用 GROUP BY 子句和SUM、AVG兩個聚合函數實現的)。
分組查詢是一種最基本的查詢,現在的主流資料庫都支持它。所以每一個學習資料庫的人都應該很好的理解它。
2. SQL語句,已建立學生表(學號,姓名,性別,專業,出生日期,高考分數)和成績表(課程號,學號,成績
1.查詢全體男學生情況,要求結果按出生日期降序排列。
select * from 學生表 s
left join 成績表 c on s.學號=c.學號
where s.性別='男' order by s.出生日期 desc
2.從學生表和成績表兩個表中,檢索所有成績多於85分的學號、姓名、課程號、學期和成績。
select s.學號,s.姓名,c.課程號,c.學期,c.成績 from 學生表 s
left join 成績表 c on s.學號=c.學號
where c.成績>=85
3.統計每個專業的學生人數
select s.專業,count(*) from 學生表 s group by s.專業
4.檢索出哪些至少有一門課程不及格學生的學號、姓名和專業。
select s.學號,s.姓名,s.專業 from 學生表 s
where exists (
select 1 from 成績表 c where s.學號=c.學號
and c.成績<60 )
3. 資料庫期末考試題 編寫SQL語句 1.創建一張學生表,包含以下信息,學號,姓名,年齡,性別,家庭住址,聯系
create table 學生表
(
學號 char(10) primary key,
姓名 char(10),
年齡 int,
性別 char(2) check (sex IN ('男','女')),
家庭住址 char(40),
聯系 char(20)
)
4. sql 學生成績表多表查詢篩選學生的問題
select
t1.*
from
t1
where
t1.id in(select t2.id from t2 where 考試名 in(『A','B') group by t2.id having count(1)=2)
and
t1.id in(select t3.id from t3 where 課程名 in('C1','C2') group by t3.id having count(1)=2)
5. sql就學生成績表的查詢問題
查詢學生XX的各個科目考試成績:
select 學號,姓名,科目名稱,科目代號,成績
from 學生表 a
inner join 成績表 b on a.學號=b.學號
inner join 科目表 c on b.科目代號=c.科目代號
where a.學號=XX
查詢各個科目考試成績的最高分的學生學號,姓名和科目及成績:
select 學號,姓名,科目名稱,科目代號,成績
from 學生表 a
inner join 成績表 b on a.學號=b.學號
inner join 科目表 c on b.科目代號=c.科目代號
where 成績=(select max(成績) from b)
查詢各個科目考試成績低於60分的學生學號,姓名和科目及成績:
select 學號,姓名,科目名稱,科目代號,成績
from 學生表 a
inner join 成績表 b on a.學號=b.學號
inner join 科目表 c on b.科目代號=c.科目代號
where 成績 in(select 成績 from b where 成績<60)
6. 求學生表和成績表的sql語句
select student_id,avg(score),max(score),min(score) from t_score GROUP BY student_id
7. 資料庫SQL語句考試
1.
create table A (
S# varchar(20) primary key,
SN varchar(20),
Sex varchar(2),
Age number(10),
Dept varchar(50));
create table B (
C# varchar(20) primary key,,
CN varchar(20));
create table C (
S# number(10),
C# number(10),
Grade number(10));
2.
insert into table A(S#,Sn,Dept) values('010102','張靜','機電');
3.
update C set grade=59 where grade>=60;
4.
delete * from C where S# in (select S# from A where Sn like '李%');
delete * from A where Sn like '李%';
5.
select S#,Sex,Age from A where Sn='劉華';
6.
select A.S#,B.C#,B.Cn from A,B,C
where A.Dept not in('計算機系','法律系') and A.S#=C.S# and C.C#=B.C#;
7.
select C.S#,sum(Grade) G from B,C
where Cn='大學語文' and B.C#=C.C# group by C.S# order by G desc;
8.
alter table A drop column Sex;//刪除列
alter table A drop Column Age;
update A set SEX='',AGE='';//刪除列記錄
(不知道你這個刪除具體是什麼意思,2種你自己選擇。)
9.
drop table C;
drop table B;
drop table A; //先刪C再刪A,否則會報錯,無法刪除使用記錄。
8. SQL 統計每個學生的選課門數和考試總成績,求各位大大指教
selecta.姓名.count(c.課程號)as選課門數,sum(c.成績)as總成績from學生表a,課程表b,成績表cwherea.學號=c.學號andb.課程號=c.課程號groupbya.姓名
9. sql語句:已知學生表student 欄位學生id 學生姓名 班級id 課程名稱 考試成績
oracle.(與sql server的sql語句主要在函數上,我記得sql server沒有nvl 有nullif)
(1)
select b.班級名稱,a.課程名稱,a.平均分 from (select 班級id,課程名稱,avg(nvl(考試成績,0)) 平均分 from student group by 班級id,課程名稱) a,class b where a.班級id=b.班級id
(2)
select * from student, (select 學生姓名,count(*) from student where 考試成績<60 group by 學生姓名 having count(*)>2) a where 考試成績<60 and student.學生姓名=a.學生姓名
10. SQL 語句查詢所有參加考試的學生,從Stu表中和Sco表中
select
*
from
score(成績表)
where
stuno(考號)
in
(select
stuno
from
student)
思路是這樣的,學生表中有的考號在成績表中出現,就叫做參加考試了,更詳細的就是說,機試和筆試成績都不為null