易截截图软件、单文件、免安装、纯绿色、仅160KB

求这句Sql如何理解

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
联系日


相关问答:

linux 下的java 程序调用sqlplus执行.sql文件乱码

                        现在我的情况是这样:

                        我的 ......

SQL语句提问

现有表  Term
结构如下

time1 time2 idterm
2009-2-15 2009-6-30 11
2009-9-10 2010-1-15 12

如果输入 2009-4-25 则应该取出idterm 11
如果输入 2009-12-5 则应该取出idterm 12 ......

linq to sql的问题

linq to sql里怎样使它在插入数据时自动截断过长的字符串而不是抛出错误
。。。。。。。。。。我通常都是提交时就检查他在长度。。。

不是,现在是项目做完了,很多模块插入数据时都出现这样的问题。以前用sqlpa ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号