Sql 为什么我在执行此查询时会获得20142015年至2016年5月的记录>;
将t1条件移动到Sql 为什么我在执行此查询时会获得20142015年至2016年5月的记录>;,sql,Sql,将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 and t1.CreateDate between '20160531
WHERE
子句:
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'
顺便说一句,您是否在字符列中存储日期?我建议改为使用
date
列。t1列。CreateDate的数据类型?@RowlandShaw,不,t1,不是t2。@RowlandShaw不是这样,其中中的两个条件都适用于第一个表t1
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'