Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 为什么我在执行此查询时会获得20142015年至2016年5月的记录>;_Sql - Fatal编程技术网

Sql 为什么我在执行此查询时会获得20142015年至2016年5月的记录>;

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

将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' 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'