我有一个带有以下列的订单表:userID和createdTime
我想列出2个月前有预订的客户,而从2个月前到现在不进行预订。
我列出了我在2个月前预订的所有客户的查询信息
SELECT userId,createdTime,FROM_UNIXTIME(createdTime)
FROM
mytable
GROUP BY userId HAVING createdTime < 1466035200
但是,在那之后我该如何过滤那些有保留的?
谢谢
最佳答案
SELECT userId
FROM mytable
GROUP BY userId
HAVING sum(FROM_UNIXTIME(createdTime) < curdate() - interval 2 month) > 0
AND sum(FROM_UNIXTIME(createdTime) > curdate() - interval 2 month) = 0