Ⅰ 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'))