Ⅰ sql查詢語句,要得到每個班每門課程的平均分,以及每個班的人數。如圖:
select 班級,avage(語文) as 語文,avage(數學) as 數學,count(*) as 人數 from table groub by 班級
Ⅱ 怎樣編寫SQL語句求平均成績
1:使用sql自帶的avg函數
語法:SELECT
AVG(column_name)
FROM
table_name
2:使用sum和count函數進行
SELECT
SUM(fJE)/COUNT(*)
as
column_name
FROM
table_name
需要條件和分組可在後面加where
條件以及group
by
分組
Ⅲ SQL怎麼查詢每門課的平均分
SQL查詢每門課的平均分的代碼:SELECT CNO,AVG(GRADE) FROM SC GROUP BY CNO。
SQL語言,是結構化查詢語言(Structured Query Language)的簡稱。SQL語言是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。
SQL語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統可以使用相同的結構化查詢語言作為數據輸入與管理的介面。SQL語言語句可以嵌套,這使他具有極大的靈活性和強大的功能。
應用信息:
結構化查詢語言SQL(STRUCTURED QUERY LANGUAGE)是最重要的關系資料庫操作語言,並且它的影響已經超出資料庫領域,得到其他領域的重視和採用,如人工智慧領域的數據檢索,第四代軟體開發工具中嵌入SQL的語言等。
標准:
SQL 是1986年10 月由美國國家標准局(ANSI)通過的資料庫語言美國標准,接著,國際標准化組織(ISO)頒布了SQL正式國際標准。1989年4月,ISO提出了具有完整性特徵的SQL89標准,1992年11月又公布了SQL92標准,在此標准中,把資料庫分為三個級別:基本集、標准集和完全集。
Ⅳ SQL求總分及平均值
SQL求總分及平均值的方法。
如下參考:
1.打開資料庫軟體,添加資料庫,右鍵點擊並選擇新查詢。
Ⅳ 在SQL語句中怎麼查詢一個科目的最高分和最低分還有平均分
select max(科目) as '最高分',min(科目) as 最低分,round(avg(科目),2) as '平均分' from 表
round(avg(科目),2) 意思是平均分保留兩位小數,因為在多個科目中就可以出現小數
如果有一科或多科沒有成績使用avg就不正確,應該用以下語句:
select max(科目) as '最高分',min(科目) as 最低分,round(sum(科目)/科目數,2) as '平均分' from 表
因為avg有效果是對已有數據的統計平均。
Ⅵ 怎樣編寫SQL語句求平均成績
1、打開資料庫軟體,附加資料庫,右鍵選擇新建查詢。
Ⅶ SQL資料庫命令,求救查詢平均成績!萬分感謝!
SQL資料庫命令,求救查詢平均成績!
select 學號, avg(分數) from grade group by 學號 having count(distinct 課程編號) > 1
select 學號 as u_編號, 姓名 as u_名稱
from student_info where 姓名 like '張%'
union
select 課程編號 as u_編號, 課程名稱 as u_名稱
from curriculum
Ⅷ 1查詢成績表的總分數,平均分,最低分和最高分。用sql語句怎麼寫
---1. 計算每個人的總成績並排名(要求顯示欄位:姓名,總成績)
select name,sum(cast(score as bigint)) as allscore from stuscore group by name order by allscore desc
---2. 計算每個人的總成績並排名(要求顯示欄位: 學號,姓名,總成績)
select stuid,name,sum(cast(score as bigint)) as allscore from stuscore group by stuid,name order by allscore desc
---3. 計算每個人單科的最高成績(要求顯示欄位: 學號,姓名,課程,最高成績)
SELECT t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(SELECT stuid,max(score) as maxscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid and t1.score=t2.maxscore
---4. 計算每個人的平均成績(要求顯示欄位: 學號,姓名,平均成績)
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(cast(score as bigint)) as avgscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid
---5. 列出各門課程成績最好的學生(要求顯示欄位: 學號,姓名,科目,成績)
select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,(select subject,max(score) as maxscore from stuscore group by subject) t2 where t1.subject=t2.subject and t1.score=t2.maxscore
---6. 列出各門課程成績最好的兩位學生(要求顯示欄位: 學號,姓名,科目,成績)
select distinct t1.* from stuscore t1 where t1.stuid in(select top 2 stuscore.stuid from stuscore where subject = t1.subject order by score desc)order by t1.subject
---7. 統計報表(要求顯示欄位: 學號,姓名,各科成績,總分,平均成績)
select stuid as 學號,name as 姓名,sum(case when subject='語文' then score else 0 end) as 語文,sum(case when subject='數學' then score else 0 end) as 數學,sum(case when subject='英語' then score else 0 end) as 英語,sum(cast(score as bigint)) as 總分,(sum(cast(score as bigint))/count(*)) as 平均分 from stuscore group by stuid,name order by 總分 desc
---8. 列出各門課程的平均成績(要求顯示欄位:課程,平均成績)
select subject,avg(cast(score as bigint)) as avgscore from stuscore group by subject
---9. 列出數學成績的排名(要求顯示欄位:學號,姓名,成績,排名)
select * from stuscore where subject ='數學' order by score desc
---10. 列出數學成績在2-3名的學生(要求顯示欄位:學號,姓名,科目,成績)
select t3.* from(select top 2 t2.* from (select top 3 name,subject,score,stuid from stuscore where subject='數學' order by score desc) t2 order by t2.score) t3 order by t3.score desc
---11. 求出李四的數學成績的排名
declare @tmp table(pm int,name varchar(50),score int,stuid int)
insert into @tmp select null,name,score,stuid from stuscore where subject='數學' order by score desc
declare @id int
set @id=0;
update @tmp set @id=@id+1,pm=@id
select * from @tmp where name='李四'
---12. 統計各科目及格人數
select subject,
(select count(*) from stuscore where score<60 and subject=t1.subject) as 不及格,
(select count(*) from stuscore where score between 60 and 80 and subject=t1.subject) as 良,
(select count(*) from stuscore where score >80 and subject=t1.subject) as 優
from stuscore t1 group by subject
---13.統計如下:數學:張三(50分),李四(90分),王五(90分),趙六(76分)
declare @s varchar(1000)
set @s=''
select @s =@s+','+name+'('+convert(varchar(10),score)+'分)' from stuscore where subject='數學'
set @s=stuff(@s,1,1,'')
print '數學:'+@s
Ⅸ 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語句的使用——查詢每個學生的總分和平均分,有一張表
select sum(grade)總成績,avg(grade) 平均成績from sc where sno in(select sno from sc where sno in('1001','1002','1003','1004','1005'))