如何将总额与金额进行比较?

发布于 2025-02-05 14:30:18 字数 352 浏览 4 评论 0原文

该表看起来像这样:

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

现在我需要一排中的数量之一的检查,并且仅在不相等的情况下显示。

The table looks like this:

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

I want to compare the sum of the amounts with the amount and only select that are not equal.

Also in the example: 15 + 20 != 40

SELECT sum(price), transactionid FROM payment group by transactionid

Now I need the check with one of the amounts from a row and show only if is unequal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2025-02-12 14:30:18

设置具有子句中的条件:

SELECT transactionid,
       SUM(price) total_price,
       MAX(amount) amount
FROM payment 
GROUP BY transactionid
HAVING total_price <> amount;

请参阅

Set the conditions in the HAVING clause:

SELECT transactionid,
       SUM(price) total_price,
       MAX(amount) amount
FROM payment 
GROUP BY transactionid
HAVING total_price <> amount;

See the demo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文