create table [客户联系表]([客户编号] varchar(2),[联系日期] datetime,[联系内容] int)
insert [客户联系表]
select 'aa','2009/01/01',111 union all
select 'bb','2009/02/01',222 union all
select 'aa','2009/03/01',333 union all
select 'aa','2009/04/01',444 union all
select 'bb','2009/05/01',555
select b.客户编号, b.联系日期,b.联系内容 from 客户联系表 b where not exists(select 1 from 客户联系表 where 客户编号=b.客户编号 and 联系日期 >b.联系日期)
结果为:aa 2009-04-01 00:00:00.000 444
bb 2009-05-01 00:00:00.000 555
求:not exists这句如何理解
不明白为啥求出来就是最后日期
不包含!!
相同客户编号,显示最近联系的
大哥,拿这个例子讲详细点
not exists 再加上联系日期 >b.联系日期,就像双重否定的意思,最后得到b的结果就是最新的联系日期
where not exists(select 1 from 客户联系表 where 客户编号=b.客户编号 and 联系日期 >b.联系日期)
相当于
where 联系日期 not in(select top 1 联系日期 from 客户联系表 where 客户编号=b.客户编号 and 联系日期 >b.联系日期)
select b.客户编号, b.联系日期,b.联系内容 from 客户联系表 b where not exists(select 1 from 客户联系表 where 客户编号=b.客户编号 and 联系日期 >b.联系日期)
客户编号=b.客户编号 结果为aa和bb
联系日
自从直接在一个表里加了个字段(nvarchar 其他默认,不插入自己默认为 <null>)后,重启网站+sql server 2000 6-8个小时后出现问题:网站写数据库时脚本超时
Active Server Pages 错误 'ASP 0113 ......
....接到一个小程序..工作原来大概是这样的...前台是WEB服务器.架构就是ASP+SQL..前台由ASP向SQL添加服务类别(表单).然后又后台程序读取表单..要实时读取..然后显示在服务器上面..从理论上面能行通不?如果可以..后台 ......