+ -
当前位置:首页 → 问答吧 → 一个排重问题

一个排重问题

时间:2011-12-14

来源:互联网

取最后联系日期:
select b.ino,b.Name,max(b.tDate) as 最后联系日期 from jilu b group by b.ino,b.Name 
结果:

388 国人 2011-09-14 09:00:00.000
389 国人 2011-09-08 09:00:00.000

为什么没有取出最大的日期呢?谢谢

app://ContactRecord?KeyField=388(对应b.id) 2986 国人 2011-09-08 00:00:00.000 97
app://ContactRecord?KeyField=389 2986 国人 2011-09-08 00:00:00.000 97

这个是取出最大了,为什么b.id会出来两个呢?我想只b.id我只想留一行啊,怎么搞出两个来了,加distinct 无效

作者: tianyazaixian   发布时间: 2011-12-14

SQL code
select * from jilu t where tDate=(select max(tDate) from jilu where ino=t.ino and name=t.name)

作者: fredrickhu   发布时间: 2011-12-14

SQL code
select * from jilu t
 where not exists (select 1 from jilu where ino=t.ino and name=t.name and tDate>t.tDate)

作者: ssp2009   发布时间: 2011-12-14

SQL code
select b.Name,max(b.tDate) as 最后联系日期 from jilu b group by b.Name 

作者: qianjin036a   发布时间: 2011-12-14