您想将条件从联接拉到
having子句中。联接 仅 查看那些日期之前的记录,因此您不知道之后是否发生任何事情。
SELECt *FROM tbldealermobiles INNER JOIN tblhistory ON tbldealermobiles.FCS = tblhistory.FCS INNER JOIN tblAllDealers ON tbldealermobiles.FCS = tblAllDealers.FCSWHERe 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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)