嗨,我在这里问了一个问题:仅返回最大值小于指定的行
我得到的答案非常适合我想要的:
SELECT *
FROM tbldealermobiles
INNER JOIN tblhistory ON tbldealermobiles.FCS = tblhistory.FCS
INNER JOIN tblAllDealers ON tbldealermobiles.FCS = tblAllDealers.FCS
WHERE tblAllDealers.CustGroup in ('Virtual', 'Outbound')
GROUP BY tbldealermobiles.mobilenumber
HAVING MAX(tblhistory.PurchaseDate) <
MAX(case when tblAllDealers.CustGroup = 'Virtual' then date('2013-03-22')
when tblAllDealers.CustGroup = 'Outbound' then date('2013-04-21')
end)
ORDER BY tblhistory.PurchaseDate DESC
我试图通过简单地将小于符号更改为大于符号来重新调整它的用途,如下所示:
SELECT *
FROM tbldealermobiles
INNER JOIN tblhistory ON tbldealermobiles.FCS = tblhistory.FCS
INNER JOIN tblAllDealers ON tbldealermobiles.FCS = tblAllDealers.FCS
WHERE tblAllDealers.CustGroup in ('Virtual', 'Outbound')
GROUP BY tbldealermobiles.mobilenumber
HAVING MAX(tblhistory.PurchaseDate) >
MAX(case when tblAllDealers.CustGroup = 'Virtual' then date('2013-03-22')
when tblAllDealers.CustGroup = 'Outbound' then date('2013-04-21')
end)
ORDER BY tblhistory.PurchaseDate DESC
但是我得到了指定日期之前的手机号码,这个查询可以这样使用还是需要重新编写?
输出 :
我得到 795 行,这是最后 15 行:
PurchaseDate CustGroup
2012-05-12 Outbound
2012-05-12 Outbound
2012-05-11 Virtual
2012-05-10 Virtual
2012-05-10 Outbound
2012-05-10 Outbound
2012-05-10 Virtual
2012-05-10 Outbound
2012-05-10 Outbound
2012-05-10 Virtual
2012-05-09 Outbound
2012-05-09 Outbound
2012-05-09 Outbound
2012-05-08 Outbound
2012-05-08 Outbound
提前致谢。