【发布时间】:2022-06-13 17:44:36
【问题描述】:
表格如下所示:
id, price, amount, transactionid
1, 5, 10, abc
2, 5, 10, abc
3, 20, 40, def
4, 20, 40, def
5, 15, 40, xyz
6, 20, 40, xyz
我想将金额的总和与金额进行比较,只选择不相等的。
同样在示例中:15 + 20 != 40
SELECT sum(price), transactionid FROM payment group by transactionid
现在我需要支票,其中包含一行中的一个金额,并且仅在不相等时才显示。
【问题讨论】:
-
用计算总和的子查询加入表。
-
* 不是免费的编码服务。你应该try to solve the problem first。请更新您的问题以在minimal reproducible example 中显示您已经尝试过的内容。如需更多信息,请参阅How to Ask,并拨打tour :)
标签: mysql group-by sum max having