gpt4 book ai didi

sql - 对一些sql帮助不大

转载 作者:行者123 更新时间:2023-12-03 01:59:23 25 4
gpt4 key购买 nike

给出下表:

rowId  AccountId  Organization1  Organization2
-----------------------------------------------
1 1 20 10
2 1 10 20
3 1 40 30
4 2 15 10
5 2 20 15
6 2 10 20

如何识别特定帐户的 Organization1 中不存在 Organization2 的记录

例如,在上面给定的数据中,我的结果将是一条记录,该记录将为 AccountId 1,因为该特定帐户的 row3 组织 2 值 30 不存在于组织 1 中。

最佳答案

SELECT rowId, AccountId, Organization1, Organization2
FROM yourTable yt
WHERE NOT EXISTS (SELECT 1 FROM yourTable yt2 WHERE yt.AccountId = yt2.AccountId AND yt.Organization1 = yt2.Organization2)

关于sql - 对一些sql帮助不大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3925488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com