首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

这样的查询语句如何写

2011-12-25 
这样的查询语句怎么写?是这样的,有一个表a,里面的数据如下:其中idint,tatidvarchar(18)workDatevarchar(16

这样的查询语句怎么写?
是这样的,有一个表a,里面的数据如下:
其中id   int,tatid   varchar(18)   workDate   varchar(16)

  id                   tatid                                       workDate
1090     200403050000000066                   2002-4--2003-11
1006     200403050000000066                   2003-11--2004-11
1007     200403050000000066                   2000-11--2002-4
1015     200403050000000075                   2002-6--2003-10
1016     200403050000000075                   NULL
1019     200403050000000075                   2004-11--2006-10
......

我想查出结果,如:

  id                   tatid                                       workDate
1006     200403050000000066                   2003-11--2004-11
1019     200403050000000075                   2004-11--2006-10
......


就是workDate最靠后的,请问怎么写?

[解决办法]
使用时间倒序,top n不就行了?
[解决办法]
select * from a order by workDate desc
[解决办法]
说实话lz说的更让人迷糊了
[解决办法]
select id,tatid,max(workDate) from a where tatid in (select distinct tatid from a)
[解决办法]
select * from a as table1,
(select max(id) as maxid from a group by id) as table2
where table1.id = table1.id order by table1.id
[解决办法]
忘了加上group by
[解决办法]
select top 2 * from a order by workDate desc
[解决办法]
select * from a where 不存在workDate比当前行大的tatid

大概就这个意思,用EXISTS多试一下。
[解决办法]
select distinct tatid from a order by workDate desc
[解决办法]
不好意思,刚才写错了,修正如下:

select * from a as table1,
(select id from a where worddate in (select max(workDate) from a group by tatid)) as table2
where table1.id = table1.id order by table1.id

热点排行