易截截图软件、单文件、免安装、纯绿色、仅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


相关文档:

vs2005中无法连接SQL问题(转)

vs2005中无法连接SQL问题
最近在研究ASP.NET,在安装VS2005和SQL上,问题多多啊,卡了我很多天,最后在查阅一堆资料和重装无数次系统之后,终于研究出为什么我不能连接数据库的问题了,解决方法如下:
  (1)开始->程序->Microsoft SQL Server 2005->SQL Server 2005外围应用配置器,在打开的界面单击"服务的连 ......

SQL 2005远程访问的设置

SQL 2005远程访问的设置
2009-02-27 08:13
1、首先打开SQL Server 外围应用配置器,点击“服务和连接的外围应用配置器”,选择数据库→远程服务,点上本地连接和远程连接,再点上同时使用tcp/ip和named pipes
2、打开SQL Server Configuration Manager,SQL Server 2005网络配置,将TCP/IP启用了。
3、一 ......

SQL——数据完整性


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

简单的3个SQL视图搞定所有SqlServer数据库字典 转

数据库字典包括表结构(分2K和2005)、索引和主键.外键.约束.视图.函数.存储过程.触发器.规则。可以在企业管理器、查询分析器中简单执行,直接了当的查出SQL2K及SQL2005的所有数据字典,方便文档的编写,希望对大家有帮助。
1. SqlServer2000数据库字典--表结构.sql
SELECT TOP 100 PERCENT --a.id,
   & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号