我有两张桌子:
表'annonce'(房地产广告):
"nombre": "Recursos hídricos",
"id": 2
"nombre": "Minero Energético",
"id": 2
"nombre": "Cobertura y uso",
"id": 2
表'freeDays'(所有广告的免费日期):
idAnnonce | reference
-----------------------
1 | dupond
2 | toto
我想选择所有在开始日期和结束日期之间只有免费天数的可投放广告,我必须在这个日期之间检查每一天。
请求:
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
没有结果。我的错误在哪里?
答案 0 :(得分:3)
它不能等于两个日期
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'
答案 1 :(得分:1)
Matt说的是正确的。你也可以这样做:
.split().tokenize("\n", 5).streaming();
或者像这样:
SELECT DISTINCT a.idAnnonce, a.reference
FROM annonce a
INNER JOIN freeDays f ON a.idAnnonce = f.idAnnonce
WHERE f.date IN('2015-06-06','2015-06-07')
这将为您提供与SELECT DISTINCT a.idAnnonce, a.reference
FROM annonce a
INNER JOIN freeDays f ON a.idAnnonce = f.idAnnonce
WHERE f.date ='2015-06-06' OR f.date ='2015-06-07'
答案 2 :(得分:0)
你的WHERE子句要求不可能!
您要求的行是'freedays'。'date'值是2015-06-06 和 2015-06-07。
AND
freeDays.date = '2015-06-06'
AND
freeDays.date = '2015-06-07'
您需要使用BETWEEN:
freeDays.date BETWEEN '2015-06-06' AND '2015-06-07'
AND
freeDays.date = '2015-06-06'
OR
freeDays.date = '2015-06-07'