然后629,628,一直到420分为止。要不要专门建个表来存放结果?还是写一段T-SQL语句就可以解决?

解决方案 »

  1.   

    select 总分,count(*) 人数 from 成绩表 
    where 总分 between 420 and 630 
    group by 总分
    order by 总分
      

  2.   

    默认值是按分数升序排序....降序的话,用order by desc
      

  3.   

    那你的表中得有 科 这个字段才行。
    把那个条件加上就行了。
    --------------------------------------------------------------
    select 总分,count(*) 人数 from 成绩表 
    where 总分 between 420 and 630 and 科='文'
    group by 总分
    order by 总分----------------------------------------------
    如果选理科,则把那个条件改成  科='理'就行了
      

  4.   

    select 总分,
    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 总分
      

  5.   

    你这个20分不真不好挣,,,呵呵,,应该一件SQL语句是不能够得到你这样的效果的。
      

  6.   

    是啊,很对不住, yanglszt(YangLing)  写得不对
      

  7.   

    usb pubs
    --建一个表写入一些测试数据.
    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累死我也,搞掂!
      

  8.   

    顶上的数据中的分数是乱填的,那个无关紧要,主要是为了测试后面的函数和select.
    -------------------------------------------------------------------------------------------------------
    你这20分,把我是搞晕了...呵呵,收工睡觉!