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'
最佳答案
将 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'
顺便说一句,您是否将日期存储在字符列中?我建议改为使用 date
列。
关于sql - 为什么我在执行此查询时得到 2014、2015 年到 2016 年 5 月的记录 >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826759/