gpt4 book ai didi

mysql - NEGATION INNER JOIN 与 WHERE

转载 作者:行者123 更新时间:2023-11-30 22:39:47 26 4
gpt4 key购买 nike

为什么下面的sql代码会忽略

WHERE r.tt_schedules_id = '105'

SELECT DISTINCT r.load_date, u.url
FROM tt_results r
INNER JOIN url_lp u
ON u.lp_id <> r.lp_id
INNER JOIN tt_schedules s
ON s.tt_schedules_id = r.tt_schedules_id
WHERE r.tt_schedules_id = '105'
AND (DATE(NOW()) - DATE(r.load_date) <= 7)

?

基本上,它返回任何内容

tt_schedules_id

有5张表:

url_lp, tt_results (table having foreign keys in url_lp, tt_schedules and tt_tags), tt_schedules, tt_tags(not used) and tt_schedules_url_lp_hub

如果你把方案画在纸上你应该清楚。

最佳答案

我修复了它:

SELECT u.url FROM url_lp u
INNER JOIN tt_schedules_url_lp_hub hub
ON hub.lp_id = u.lp_id
INNER JOIN tt_schedules s
ON hub.tt_schedules_id = s.tt_schedules_id
WHERE s.tt_schedules_id = '105'
AND u.lp_id NOT IN
(SELECT r.lp_id FROM tt_results r WHERE r.tt_schedules_id = '105')

干杯。

关于mysql - NEGATION INNER JOIN 与 WHERE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31425928/

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