再会。
在此处检查表的结构。
我想选择:
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 可以在这里找到
请告诉我如何编写正确的 SQL 选择?