【发布时间】:2013-07-05 15:43:26
【问题描述】:
美好的一天。
检查表here的结构。
我要选择:
select `idn` order by sum DESC,
where sum = (value amount where type = marks and status = up) - (value amount where type = marks and status = down)
为此,我使用 SQL:
select idn from Balans as outerB WHERE idn ! = '' group by idn order by
ifnull((select sum(innerB.amount) from Balans as innerB
where innerB.idn = outerB.idn
and type='up'), 0) -
ifnull((select sum(innerB.amount) from Balans as innerB
where innerB.idn = outerB.idn
and type='down'), 0) DESC
limit 5
但在 SQL 中不正确ORDER by ... DESC
例如,在我的示例中,结果应该是:
187113012
6299927
可以在here找到测试SQL
请告诉我如何编写正确的 SQL 选择?
【问题讨论】:
标签: mysql