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)
将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专栏.