select * from 客户表 t where not exists(select 1 from 合同表 where 客户名称=t.客户名称) and datediff(day,建档日期 ,getdate())>30
SELECT A.* FROM 客户表 A LEFT JOIN 合同表 B WHERE B.客户名称=A.客户名称 AND DATEDIFF(DD,建档日期,签订合同日期)>30
--猜测的 select * from 客户表 where 客户名称 not in (select 客户名称 from 合同表) and datediff(dd,建档日期,getdate())>=30
select t.* from 客户表 t where 客户名称 not in (select m.客户名称 from 客户表 m ,合同表 n where m.客户名称 = n.客户名称 and datediff(m.建档日期,签订合同日期) <= 30 )select t.* from 客户表 t where 客户名称 not in (select 客户名称 from 合同表)
SQL77 为什么会提示语错误啊/?
SELECT A.* FROM 客户表 A LEFT JOIN 合同表 B on B.客户名称=A.客户名称 AND DATEDIFF(DD,建档日期,签订合同日期)>30
--这样呢? SELECT A.* FROM 客户表 A LEFT JOIN 合同表 B WHERE B.客户名称=A.客户名称 AND DATEDIFF(DD,a.建档日期,b.签订合同日期)>30
--> 测试数据:@table1 declare @table1 table([客户名称] varchar(3),[建档日期] varchar(10)) insert @table1 select '001','2009-10-01' union all select '002','2009-09-01' union all select '003','2009-10-02' union all select '004','2009-11-11'--> 测试数据:@table2 declare @table2 table([客户名称] varchar(3),[签订合同日期] varchar(10)) insert @table2 select '001','2009-10-30' union all select '002','2009-11-01'select * from @table1 where 客户名称 not in (select 客户名称 from @table2) and datediff(day,建档日期,getdate()) > 30 --结果 003 2009-10-02
where not exists(select 1 from 合同表 where 客户名称=t.客户名称)
and datediff(day,建档日期 ,getdate())>30
FROM 客户表
A LEFT JOIN 合同表 B
WHERE B.客户名称=A.客户名称
AND DATEDIFF(DD,建档日期,签订合同日期)>30
select
*
from
客户表
where
客户名称
not in
(select 客户名称 from 合同表)
and
datediff(dd,建档日期,getdate())>=30
(select m.客户名称 from 客户表 m ,合同表 n where m.客户名称 = n.客户名称 and datediff(m.建档日期,签订合同日期) <= 30 )select t.* from 客户表 t where 客户名称 not in (select 客户名称 from 合同表)
为什么会提示语错误啊/?
FROM 客户表
A LEFT JOIN 合同表 B
on B.客户名称=A.客户名称
AND DATEDIFF(DD,建档日期,签订合同日期)>30
SELECT
A.*
FROM
客户表 A LEFT JOIN 合同表 B
WHERE
B.客户名称=A.客户名称
AND
DATEDIFF(DD,a.建档日期,b.签订合同日期)>30
declare @table1 table([客户名称] varchar(3),[建档日期] varchar(10))
insert @table1
select '001','2009-10-01' union all
select '002','2009-09-01' union all
select '003','2009-10-02' union all
select '004','2009-11-11'--> 测试数据:@table2
declare @table2 table([客户名称] varchar(3),[签订合同日期] varchar(10))
insert @table2
select '001','2009-10-30' union all
select '002','2009-11-01'select * from @table1
where 客户名称 not in (select 客户名称 from @table2)
and datediff(day,建档日期,getdate()) > 30
--结果
003 2009-10-02