當前位置:首頁 » 編程語言 » 查詢李強的平均成績sql
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

查詢李強的平均成績sql

發布時間: 2022-11-13 04:13:23

A. 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標准,在此標准中,把資料庫分為三個級別:基本集、標准集和完全集。

B. 如何用SQL語句查詢各門課程的平均成績

創建表:

SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[stuscore]

( [name] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,

[subject] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,

[score] [int] NULL,

[stuid] [int] NULL)

ON [PRIMARY]

GO

SET ANSI_PADDING OFF

插入數據:

insert into dbo.stuscore values ('張三','數學',89,1);

insert into dbo.stuscore values ('張三','語文',80,1);

insert into dbo.stuscore values ('張三','英語',70,1);

insert into dbo.stuscore values ('李四','數學',90,2);

insert into dbo.stuscore values ('李四','語文',70,2);

insert into dbo.stuscore values ('李四','英語',80,2);

查詢結果如下:

列出各門課程的平均成績:

select subject,AVG(score)平均成績 from stuscore
group by subject;

C. sql題 查詢每位同學的課程門數、總成績、平均成績」的SQL語句是什麼

不知道你的表結構是什麼啊?
例如表的欄位有姓名、課程、成績的話
每人的總成績:SELECT 姓名,SUM(成績) FROM 表名 GROUP BY 姓名
每人的平均成績:SELECT 姓名,SUM(成績)/COUNT(*) FROM 表名 GROUP BY 姓名
每人的課程門數:SELECT 姓名,COUNT(*) FROM 表名 GROUP BY 姓名

D. 怎樣編寫SQL語句求平均成績

1、打開資料庫軟體,附加資料庫,右鍵選擇新建查詢。

E. SQL求每個學生平均成績

selects,學號,s,姓名,c,課程名,t,平均成績

fromstudentass

leftjion

selectavg(成績)as平均成績,學號

fromscgroupby學號

)astont,學號=s,學號

leftjoinsconsc。學號=s,學號

leftjoincourseasconc。課程號=sc,課程號

功能:

SQL具有數據定義、數據操縱和數據控制的功能。

1、SQL數據定義功能:能夠定義資料庫的三級模式結構,即外模式、全局模式和內模式結構。在SQL中,外模式又叫做視圖(View),全局模式簡稱模式(Schema),內模式由系統根據資料庫模式自動實現,一般無需用戶過問。

2、SQL數據操縱功能:包括對基本表和視圖的數據插入、刪除和修改,特別是具有很強的數據查詢功能。

以上內容參考:網路-結構化查詢語言

F. 查詢每位同學的課程門數、總成績、平均成績」的SQL語句是什麼

SQL語句如下:

SELECT 學號, Count(課程編號) AS 課程總數, Sum(成績) AS 總分數, Avg(成績) AS 平均分

FROM 成績表

GROUP BY 學號;

SQL常用操作語句如下:

選擇:select * from table1 where 范圍

插入:insert into table1(field1,field2) values(value1,value2)

刪除:delete from table1 where 范圍

更新:update table1 set field1=value1 where 范圍

查找:select * from table1 where field1 like 』%value1%』

排序:select * from table1 order by field1,field2 [desc]

總數:select count as totalcount from table1

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

最大:select max(field1) as maxvalue from table1

最小:select min(field1) as minvalue from table1

G. 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

H. sql查詢姓李的學生的平均成績

工具/材料:Management Studio。

1、首先在桌面上,點擊「Management Studio」圖標。

I. 用SQL語言查詢每位同學的平均成績,要求學號、姓名和平均成績。怎麼做,急!!!

select姓名,學號,avg(科目成績+科目成績..+N)from表名
groupby姓名,學號