然后629,628,一直到420分为止。要不要专门建个表来存放结果?还是写一段T-SQL语句就可以解决?
解决方案 »
- 急救 如何把多列合一个列显示
- 数据库
- 关于parameter.value赋值自动加引号的问题
- 怎样在使用链接服务器建立远程数据库上表的索引?
- 请问如何把dbf数据库导入sql server 2000数据库
- 使用openrowset把vfp的DBF文件导入导出SQL SERVER的问题
- sql统计语句什么写??——————小问题大用处啊~~~
- 远程管理SQL库时如何把库表中信息保存下来?整表删后如何恢复这个表
- 左外连接的奇怪问题,同一条记录的值也不同
- 存储过程错误
- 数据库设计必须知道的问题
- MS-SQL2000 程序文件C盘|数据文件D盘。D盘有坏道。需要把数据文件转移到F盘。现在问题是如何修改数据文件存储目录?
where 总分 between 420 and 630
group by 总分
order by 总分
把那个条件加上就行了。
--------------------------------------------------------------
select 总分,count(*) 人数 from 成绩表
where 总分 between 420 and 630 and 科='文'
group by 总分
order by 总分----------------------------------------------
如果选理科,则把那个条件改成 科='理'就行了
count(case when 总分 between 420 and 630 and 科='文' then 总分 end) as [420-630(文)],
count(case when 总分 between 420 and 630 and 科='理' then 总分 end) as [420-630(理)],
……
from 成绩表
group by 总分
--建一个表写入一些测试数据.
Create table tb (总分 int)
insert tb select 420
union all select 421
union all select 431
union all select 433
union all select 489
union all select 501
union all select 502
union all select 503
union all select 580
union all select 601
GO--取得累计值的函数
CREATE FUNCTION GetTotal(@iValue int)
RETURNS int
AS
BEGIN
DECLARE @iRe int
SELECT @iRe=count(*) from tb where 总分>=@iValue
RETURN (@iRE)
END
GO--查询+调用函数
select 总分,count(总分)as 小计,dbo.Gettotal(总分) 累计 from tb
group by 总分
order by 总分 descdrop table tb
GO累死我也,搞掂!
-------------------------------------------------------------------------------------------------------
你这20分,把我是搞晕了...呵呵,收工睡觉!