美好的一天。如何在SQL select中写入正确的ORDER BY ... DESC?
检查表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
测试SQL可能被发现here
请告诉我如何编写正确的SQL select?