易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL统计大全收藏版 个人使用

文章来源:IT工程技术网, 全文链接:http://www.systhinker.com/html/81/n-11481.html
1.计算每个人的总成绩并排名
select name,sum(score) as allscore from stuscore group by name order by allscore
2.计算每个人的总成绩并排名
select distinct t1.name,t1.stuid,t2.allscore from stuscore t1,( select stuid,sum(score) as allscore from stuscore group by stuid)t2where t1.stuid=t2.stuidorder by t2.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) t2where t1.stuid=t2.stuid and t1.score=t2.maxscore
4.计算每个人的平均成绩
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(score) as avgscore from stuscore group by stuid) t2where 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) t2where t1.subject=t2.subject and t1.score=t2.maxscore
6.列出各门课程成绩最好的两位学生
select distinct t1.* from stuscore t1 where t1.id in (select top 2 stuscore.id 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(score) as 总分,(sum(score)/count(*)) as 平均分from stuscoregroup by stuid,name order by 总分desc
8.列出各门课程的平均成绩
select subject,avg(score) as avgscore from stuscoregroup by subject
9.列出数学成绩的排名
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 sc


相关文档:

sql调优之 寻找我们最感兴趣的语句

Tuning an Application / Reducing Load
If your whole application is performing suboptimally, or if you are attempting to
reduce the overall CPU or I/O load on the database server, then identifying
resource-intensive SQL involves the following steps:
1. Determine which period in the day you would ......

Microsoft SQL Server 2005 JDBC Driver 1.1

Microsoft SQL Server 2005 JDBC Driver
1.1
快速描述
下载 Microsoft SQL Server
2005 JDBC Driver 1.1,这是一种 Type 4 JDBC 驱动程序,可通过 J2EE(Java2 企业版)中的标准 JDBC
应用程序编程接口 (API) 提供数据库链接。
本页内容

速详细信息



统要求



关资源

他用户正在 ......

SQL——数据完整性


一.数据完整性
     就是为了防止数据库中存在不符合语义规定的数据,和防止因输入输出错误而造成的无效操作或者错误信息而提出的,制定的一些对元组、属性和域的一些约束和规定。
     解决办法由:规则,默认值,约束和触发器等。
二.约束
    ......

求助SQL SERVER 2008连接问题

测试机test安装的是windows server2008+sql server 2008,数据库安装成功。可以连接局域网内其他机器的数据库(其他机器的数据库为SQL 2005)。但是网内其他机器访问test时,无法连接,报错。信息为:在建立与服务器的连接时出错。在连接到SQL SERVER 2005时,在默认的设置下SQL SERVER 不允许进行远程连接可能会导致次失败 ......

一次神奇的SQL 错误调试经历

上周接到一个奇怪的bug,一个曾经运行得很好的存储过程突然产生了错误的结果。
负责维护的兄弟们很负责任的对错误进行了跟踪,并把错误定位一个如下的语句:
SELECT *
into SomeTable
from A join B on A.id=B.id
         join C on A.id=C.id
他们发现从SomeTable做查询的 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号