为什么我在执行此查询时获得2014年至2015年的记录,直至2016年5月

Anu*_*and 2 sql

select t1.InvoiceNumber ,t1.LocalAmount  , t2.LineAmount as discount , t1.CreateDate
from CashOrderTrn t1 
left join DistrubutedDiscountDetails t2 
    on t1.InvoiceNumber =  t2.InvoiceNumber  
    and t1.CreateDate between '20160531' and  '20160701' 
    and t1.InvoiceType ='31'
Run Code Online (Sandbox Code Playgroud)

jar*_*rlh 7

将t1条件移动到WHERE子句:

select t1.InvoiceNumber ,t1.LocalAmount , t2.LineAmount as discount ,
      t1.CreateDate
from CashOrderTrn t1
left join DistrubutedDiscountDetails t2 on t1.InvoiceNumber = t2.InvoiceNumber
WHERE t1.CreateDate between '20160531' and '20160701' and t1.InvoiceType ='31'
Run Code Online (Sandbox Code Playgroud)

顺便说一句,你在字符列中存储日期吗?我推荐一个date专栏.