Ⅰ sql求每個學生平均成績
selects,學號,s,姓名,c,課程名,t,平均成績
fromstudentass
leftjion
(
selectavg(成績)as平均成績,學號
fromscgroupby學號
)astont,學號=s,學號
leftjoinsconsc。學號=s,學號
leftjoincourseasconc。課程號=sc,課程號
功能:
SQL具有數據定義、數據操縱和數據控制的功能。
1、SQL數據定義功能:能夠定義資料庫的三級模式結構,即外模式、全局模式和內模式結構。在SQL中,外模式又叫做視圖(View),全局模式簡稱模式(Schema),內模式由系統根據資料庫模式自動實現,一般無需用戶過問。
2、SQL數據操縱功能:包括對基本表和視圖的數據插入、刪除和修改,特別是具有很強的數據查詢功能。
以上內容參考:網路-結構化查詢語言
Ⅱ 按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句
按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句示例如下:
selectA.name ,
(selectB.scorefromtable_scoreBwhereB.type='數學'andA.id=B.id) as數學 ,
(selectB.scorefromtable_scoreBwhereB.type='語文'andA.id=B.id) as語文,
(selectB.scorefromtable_scoreBwhereB.type='英語'andA.id=B.id)as英語,
(selectSUM(B.score)fromtable_scoreBwhereA.id=B.id)assum_score
fromtable_studentAorderbysum_scoreDESC
以上sql語句首先把學生表和成績表聯合查出每個學生的數學、語文、英語成績,然後通過selectSUM(B.score)fromtable_scoreBwhereA.id=B.id查出每個學生的總成績。
最後orderbysum_scoreDESC實現按總成績倒敘排列。
(2)sql學生成績分段擴展閱讀
上述sql語句重點是對as關鍵字的使用- Alias(別名),通過使用 SQL,可以為列名稱和表名稱指定別名(Alias)。
表的 SQL Alias 語法
SELECT column_name(s) FROM table_name AS alias_name;
列的 SQL Alias 語法
SELECT column_name AS alias_name FROM table_name;
Alias 實例: 使用表名稱別名
假設我們有兩個表分別是:"Persons" 和 "Proct_Orders"。我們分別為它們指定別名 "p" 和 "po"。
現在,我們希望列出 "John Adams" 的所有定單。
我們可以使用下面的 SELECT 語句:
SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Proct_Orders AS poWHERE p.LastName='Adams' AND p.FirstName='John'
Ⅲ 用sql語言輸入,查找成績在70到80分之間的學生的學習情況
我先假定你有一個資料庫,表名叫student_score,成績是score,學習情況是study(如果不只一個欄位你自行添加吧)
select study from student_score where score > 70 and score < 80;
Ⅳ sql怎麼寫統計各分數段的人數
sql怎麼寫統計各分數段的人數
select count(case 分數欄位 when 100 then 1 end) as [滿分],
count(case when 分數欄位 between 90 and 99 then 1 end) as[90-99分],
count(case when 分數欄位 between 80 and 89 then 1 end) as[80-89分],
count(case when 分數欄位 between 70 and 79 then 1 end) as[70-79分],
count(case when 分數欄位<70 then 1 end) as[70分以下]
from 學生分數表
Ⅳ 怎麼用SQL的查詢語句列出某同學所有課程的課程名和成績啊,並按成績從低到高排序啊
1、打開Microsoft SQL Server 2012,選中需要查詢所有表的資料庫。
Ⅵ sql語句列出成績在80分到100分之間的學生名單
select * from 學生表 where 學生表主鍵id in (select 學生表學生id from 成績表 where 成績欄位 between 80 and 100)
或
select * from 學生表 where 學生表主鍵id in (select 學生表學生id from 成績表 where 成績欄位>=80 and 成績欄位<=100)
Ⅶ 是否可以用sql語句實現分數的分段人數統計
--結果一條記錄的方法
select sum(case when score<10 then 1 else 0 end) as [0-10],
sum(case when score>=10 and score<20 then 1 else 0 end) as [10-20],
sum(case when score>=20 and score<30 then 1 else 0 end) as [20-30],
sum(case when score>=30 and score<40 then 1 else 0 end) as [30-40],
....
from student_score
Ⅷ sql怎麼統計某一課程的各分數段的人數(在php程序里)
實現上面sql查詢結果的記錄總數
$sql = select count(C.`cid`) as `c` from (select * from `ctable` group by pid) as C left join `ptable` as P on P.`pid` = C.`pid`;
詳解,此語句用到了sql子查詢,先使用子查詢對ctable進行分組查詢,然後對分組後的結果集進行統計.
Ⅸ sql語句的使用——查詢每個學生的總分和平均分,有一張表
select sum(grade)總成績,avg(grade) 平均成績from sc where sno in(select sno from sc where sno in('1001','1002','1003','1004','1005'))
Ⅹ 如何用sql語句查出學生表成績小於60為不及格60-80為良好80-90為優秀
select name,case when 成績<60 then 不及格 when 成績>=60 and 成績<80 then 良好 when 成績>=0 and 成績<90 then 優秀 end as 成績情況 ,from 表名。
注意,在輸入sql語句的時候,要在英文環境下輸入。否則可能會出現代碼不識別。