我需要按位置获取促销信息,其中包含以下逻辑:
City = Oslo, Country = No : True
City = '', Country = No : True
City = Bergen, Country = No : False
我到目前为止的查询是这样的:
SELECT *
FROM promotion
WHERE date_start <= DATE_ADD(CURDATE(), INTERVAL 14 DAY)
AND date_end >= CURDATE()
AND fk_countryID = 'NO'
order by date_start ASC
返回5行
- 一旦城市空白。
- 一个城市是卑尔根
通缉结果:一行空白的4行。
我也试过这个:
SELECT id, name, city, fk_countryID, date_start, date_end
FROM promotion
WHERE date_start <= DATE_ADD(CURDATE(), INTERVAL 14 DAY)
AND date_end >= CURDATE()
AND city = '' || city = 'Oslo'
AND fk_countryID = 'NO'
order by date_end ASC
这会返回city为空白或“Oslo”且country id为“no”的所有行,但它也会返回日期约束之外的行。
我怎样才能做到这一点?任何帮助表示赞赏。
答案 0 :(得分:0)
我最终找到了答案:
SELECT id, name, city, fk_countryID, date_start, date_end
FROM promotion
WHERE date_start <= DATE_ADD(CURDATE(), INTERVAL 14 DAY)
AND date_end >= CURDATE()
AND city IN ('','Oslo')
AND fk_countryID = 'NO'
order by date_end ASC