select * from 表 a
order by (select sum(分数) from 表 where 学号=a.学号)

解决方案 »

  1.   

    --测试--测试数据
    create table 表(姓名 varchar(10),学号 char(4),分数 int,课程 varchar(10))
    insert 表 select 'a','1100',97,'数学'
    union all select 'a','1100',70,'英语'
    union all select 'a','1100',80,'政治'
    union all select 'b','1102',66,'数学'
    union all select 'b','1102',77,'英语'
    go--查询
    select * from 表 a
    order by (select sum(分数) from 表 where 学号=a.学号)
    go--删除测试
    drop table 表/*--测试结果
    姓名         学号   分数          课程         
    ---------- ---- ----------- ---------- 
    b          1102 66          数学
    b          1102 77          英语
    a          1100 97          数学
    a          1100 70          英语
    a          1100 80          政治(所影响的行数为 5 行)
    --*/
      

  2.   

    --如果要按总从大到小,则改为:select * from 表 a
    order by (select sum(分数) from 表 where 学号=a.学号) desc
      

  3.   

    select a.xm,a.xh,a.fs,a.kc,b.zf
      from xs_tab a
          ,(select xh,sum(fs) zf from xs_tab group by xh) b
      where a.xh=b.xh
      order by b.zf
     
      升降序自己确定
      

  4.   

    select 姓名,学号,sum(分数) as 总分
    from 表
    group by 姓名,学号
    order by sum(分数)    desc
      

  5.   

    我看 Rewiah(乘长风) 写的更明了,排序的同时把总分也计算出来了
      

  6.   

    select 姓名,学号,sum(分数) as 总分,avg(分数) as 平均分
    from 表
    group by 姓名,学号
    order by avg(分数)    desc平均分 还更合理些!咣当是谁拿砖头砸我?有种站出来!
      

  7.   

    select '姓名'=a,'总分'=sum(b) from tab group by(a) order by '总分' desc