是否可以删除总和为 0 的行?
这是表格:
+-----------+--------------+
| Subledger | ActualAmount |
+-----------+--------------+
| WWE12 | -25775 |
| WWE12 | -217 |
| WWE12 | -43 |
| WWE12 | 260 |
| WWE12 | 48994 |
+-----------+--------------+
期望的结果应该是:
+-----------+--------------+
| Subledger | ActualAmount |
+-----------+--------------+
| WWE12 | -217 |
| WWE12 | -43 |
| WWE12 | 260 |
+-----------+--------------+
非常感谢对此的任何帮助。
非常感谢!
最佳答案
这很做作,因为我事先知道总和由 3 个值组成,但无论如何......
SELECT x.*
FROM
( SELECT DISTINCT GROUP_CONCAT(DISTINCT c.actualamount ORDER BY c.actualamount) members
, SUM(DISTINCT c.actualamount) total
FROM my_table a
JOIN my_table b
ON b.actualamount NOT IN (a.actualamount)
JOIN my_table c
ON c.actualamount NOT IN (a.actualamount,b.actualamount)
GROUP
BY a.actualamount
, b.actualamount
HAVING total = 0
) n
JOIN my_table x
ON FIND_IN_SET(actualamount,members) > 0;
关于mysql - SQL - 是否可以查找具有相同分组依据的等于 0 的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45943733/