gpt4 book ai didi

mysql - 从MySQL中选择表中不包含的记录WHERE id

转载 作者:行者123 更新时间:2023-11-29 21:50:00 26 4
gpt4 key购买 nike

我需要帮助...我在 MySQL 中有三个表:price_tableitem_tabletariff_table,其中记录:

item_table中记录:

id_item | name_item
1 | Item A
2 | Item B
3 | Item C
4 | Item D
5 | Item E

tariff_table中记录:

id_tariff | name_tariff
1 | normal
2 | promo

price_table中记录:

id_price | id_item | id_tarif
1 | 1 | 1
2 | 2 | 1
3 | 3 | 1
4 | 4 | 1
5 | 5 | 1
6 | 1 | 2
7 | 2 | 2

我想选择没有 id_tariff = 2id_item

最佳答案

您可以自行加入。

SQLFiddle Demo

这是输出: enter image description here

SELECT T.id_price,item_table.name_item
FROM
price_table T
INNER JOIN item_table ON T.id_item = item_table.id_item
LEFT JOIN
(SELECT T1.*
FROM
price_table T1
INNER JOIN price_table T2 ON T1.`id_item`= T2.`id_item` AND T1.`id_tarif` <> T2.`id_tarif`) Dup ON T.`id_item` = Dup.`id_item`
WHERE Dup.`id_item` IS NULL

希望这有帮助。

关于mysql - 从MySQL中选择表中不包含的记录WHERE id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33740498/

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