(以下模式已经作压缩减少的问题)MySQL的检查是否有任何行在日期未来
我有两个表Products
:
| ID | ProductName | AvailableDate (date)
|------------------------------------------------
| 1 | Foo | 2011-01-01
| 2 | Bar | 2017-01-01
| 3 | FooBar | 2011-01-01
和Mappings
:
| ID | ProductID | SomeOtherID
|------------------------------------------------
| 1 | 1 | 1
| 2 | 2 | 1
| 3 | 3 | 2
映射可以指向n
产品:
SELECT
GROUP_CONCAT(`Products`.ProductName SEPARATOR ', ')
FROM
Mappings
JOIN
Products ON Mappings.ProductID = Products.ID
GROUP BY
Mappings.SomeOtherID
我现在想要扩展查询,以检查是否任何Products
行有一个AvailableDate比当前日期现货组合产品,即至少有一个更大的“早期访问”产品。
我尝试以下
SELECT
GROUP_CONCAT(`Products`.ProductName SEPARATOR ', '),
IF(COUNT(DATEDIFF(`Products`.AvailableDate, CURDATE)) > 0, 1, 0) As IsEarlyAccess
FROM
Mappings
JOIN
Products ON Mappings.ProductID = Products.ID
GROUP BY
Mappings.SomeOtherID
但我总是收到IsEarlyAccess = 1
。任何提示?
多谢了 - 这么简单,但如此有效!奇迹般有效 – ElGauchooo