select sum(costs) as acosts from 表名 where 条件 order by sum(costs) desc
没有错误啊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 行)
大意了,大家原谅。应该是这样sql="select sum(costs) as acosts from 表名 where 条件 group by 某个字段 order by acosts desc"
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 行)