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

子查询是在一个查询内的查询。子查询的结果被DBMS使用来决定包含这个子查询的高级查询的结果。在子查询的最简单的形式中,子查询呈现在另一条SQL语句的WHERE或HAVING子局内。 
    列出其销售目标超过各个销售人员定额综合的销售点。
SELECT CITY
from OFFICES
WHERE TARGET&nbs ......

常用的WORDPRESS 的SQL语句


下面所有的SQL语句都是针对前缀为wp_的表,如果你的表前缀不是wp_,请做相应的修改
1.更改wordpress安装和首页地址
如果你更换域名或者把wordpress的安装目录进行了变动就需要进行修改,
UPDATE wp_options SET option_value = replace(option_value, ‘旧网址’, ‘新网址’) WHERE option_name ......

SQL查询优化

基于索引的SQL语句优化之降龙十八掌
1         前言
客服业务受到SQL语句的影响非常大,在规模比较大的局点,往往因为一个小的SQL语句不够优化,导致数据库性能急剧下降,小型机idle所剩无几,应用服务器断连、超时,严重影响业务的正常运行。因此,称低效的SQL语句为客服业务的 ......

sa登陆失败 SQL Server错误18456的解决方法

昨天我的SQL(Microsoft SQL Server 2005 )登录不上去了,原来是出现了几个小问题,现在记录一下我的解决这几个情况的办法。(解决方法有很多种,这些只是我的解决方法,仅供参考)
查找问题的过程:(注:用windows账号还是可以登录的)
第一步:启动所有与SQL有关的服务,问题依旧;
第二步:查看windows防火墙,被默 ......

存储过程, 生成SQL语句

USE [sfaecrm]
GO
/****** 对象:  StoredProcedure [dbo].[proc_insert]    脚本日期: 05/29/2009 06:16:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[proc_insert] (@tablename varchar(256))
as
begin
        set ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号