日期:2014-05-19  浏览次数:20373 次

急问怎样查找数据的问题,请大侠帮忙
我在表A中有三个字段F1,F2,F3,数据类似如下
F1     F2     F3
1       B       2006-01-02
1       C       2006-01-01
2       K       2006-02-02
2       J       2006-01-12
2       M       2006-01-02
3       C       2006-02-14
3       D       2006-01-04

我要得到的数据是:
1       B       2006-01-02
2       K       2006-02-02
3       C       2006-02-14
即是说通过F1,F3   排序然后得出居于F1唯一的记录,请问用什么方法快速实现?谢谢!

------解决方案--------------------
select F1,F2=(select top 1 F2 from A where F2=B.F2),F3 from A B order by F1,F3
------解决方案--------------------
select F1,F2=(select top 1 F2 from A where F2=B.F2),F3 from A B order by F1,F3 desc
------解决方案--------------------
select F1,F2,F3
from 表A a1
where F3 = (select max(F3) from 表A where F1=a1.F1)
------解决方案--------------------
select F1,F2,F3 from 表A a1 where F3 = (select max(F3) from 表A where F1=a1.F1)

select F1,F2=(select top 1 F2 from A where F1=B.F1 order by F1,F3 desc),F3 from A B

呵呵 觉得都已样 按理说他还少了个order by F1