我正在尝试编制一个"无卖家的列表",我收到一份不同卖家名单的清单,并将其与卖家列表进行比较"又名account_manager_sellers
使用NOT IN子句,但这对我不起作用。
表plans
:
+----+-----------+
| id | seller_id |
+----+-----------+
| 1 | 1001 |
| 2 | 1002 |
| 3 | 1002 |
| 4 | 1001 |
| 5 | 1005 |
+----+-----------+
表account_manager_sellers
:
+------+--------------+
| id | persons_name |
+------+--------------+
| 1001 | name_1 |
| 1002 | name_2 |
| 1003 | name_3 |
| 1004 | name_4 |
| 1005 | name_5 |
+------+--------------+
+------+--------------+
| id | persons_name |
+------+--------------+
| 1003 | name_3 |
| 1004 | name_4 |
+------+--------------+
SELECT DISTINCT(p.seller_id) FROM plans p
WHERE p.seller_id NOT IN (
SELECT a.id FROM account_manager_sellers a
)
此代码段正在运行但未返回任何结果。
答案 0 :(得分:1)
你是在倒退吗?
<强> SQL DEMO: 强>
SELECT a.id, persons_name
FROM account_manager_sellers a
WHERE a.id NOT IN (
SELECT DISTINCT p.seller_id FROM plans p
);
<强>输出强>
| id | persons_name |
|------|--------------|
| 1003 | name_3 |
| 1004 | name_4 |