首先,这里的别名可以直接用的,应该没有错误的。其次,你这么写,汇总出来的结果只有一行,没有必要用Order By 啊。

解决方案 »

  1.   

    select isnull(sum(costs),0)  as acosts from 表名
      

  2.   

    select sum(costs) as acosts from 表名 where 条件 order by sum(costs) desc
      

  3.   

    没有错误啊CREATE TABLE A(
    ID INT IDENTITY,
    USERNAME VARCHAR(10),
    AGE INT
    )
    INSERT INTO A VALUES('tom',25)
    INSERT INTO A VALUES('jim',25)
    INSERT INTO A VALUES('tim',65)
    INSERT INTO A VALUES('jacky',33)
    INSERT INTO A VALUES('jacky',33)
    INSERT INTO A VALUES('tim',65)---查询
    select sum(id) as acosts from A 
    order by acosts desc--结果acosts      
    ----------- 
    10(所影响的行数为 1 行)
      

  4.   

    大意了,大家原谅。应该是这样sql="select sum(costs) as acosts from 表名 where 条件 group by 某个字段 order by acosts desc"