写一条SQL语句(200分)

F

fsivanl

Unregistered / Unconfirmed
GUEST, unregistred user!
请教一下:写一条SQL语句,汇总一份表中的某一字段后,再根据该字段排序该怎样写?
select custom,sum(je) as je from account group by custom order by je 这样写是非法的。
 
select custom, je
from
(
select custom,sum(je) as je from account group by custom
)
order by je
 
可能是因为 sum(je) as je后面的名称不能与已有的重复的缘故吧?
你试试:
select custom,sum(je) as jesum from account group by custom order by jesum
 
tseug is right!
 
select custom,sum(je) as je from account group by custom order by sum(je)
这样就可以了
 
select custom, je
from
(
select custom,sum(je) as je from account group by custom
)
order by je
这种语句能执行吗?为什么我这里不行
 
你是什么数据库?
 
我在sqlserver中测试了一下语句:
select custom,sum(je) as je from account group by custom order by je
是可以的,你是用的什么数据库?提示什么错误信息?要么试一下下列语句:
select custom,sum(je) as je from account group by custom order by 2
 
问题解决了!多谢大家的帮忙[:)]
 
子查询问题!
 
to tseug
我用的就是MS SQL Server 7.0
 
顶部