gpt4 book ai didi

mysql - 选择 2 个表没有返回结果?

转载 作者:行者123 更新时间:2023-11-29 01:39:09 24 4
gpt4 key购买 nike

我有 2 个表:

表“annonce”(房地产广告):

idAnnonce  |  reference
-----------------------
1 | dupond
2 | toto

表 'freeDays'(所有广告的免费天数):

idAnnonce  |  date
-----------------------
1 | 2015-06-06
1 | 2015-06-07
1 | 2015-06-09
1 | 2015-06-10
2 | 2015-06-06
2 | 2015-06-07
2 | 2015-06-12
2 | 2015-06-13

我想选择在开始日期和结束日期之间只有免费天数的所有可用广告,我必须检查此日期之间的每一天。

请求:

    SELECT DISTINCT
`annonce`.`idAnnonce`, `annonce`.`reference`
FROM
`annonce`, `freeDays`
WHERE
`annonce`.`idAnnonce` = `freeDays`.`idAnnonce`
AND
`freeDays`.`date` = '2015-06-06'
AND
`freeDays`.`date` = '2015-06-07'

不返回任何结果。我的错误在哪里?

最佳答案

两个日期不能相等

SELECT DISTINCT a.idAnnonce, a.reference 
FROM annonce a
INNER JOIN freeDays f ON a.idAnnonce = f.idAnnonce
WHERE f.date BETWEEN '2015-06-06' AND '2015-06-07'

关于mysql - 选择 2 个表没有返回结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30620680/

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