仅返回最大值小于指定值的行

仅返回最大值小于指定值的行,第1张

仅返回最大值小于指定值的行

您想将条件从联接拉到

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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5640526.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存