日期:2014-05-18  浏览次数:20372 次

紧急!如何写SQL取得我想要的数据?请各位帮帮忙,谢谢了!
数据格式如下:

accountname           date
        a                   07-5-1
        a                   07-5-2
        a                   07-5-3
        a                   07-5-4
        b                   07-5-2
        b                   07-5-3
        b                   07-5-4
        c                   07-5-9
        c                   07-5-8

我想得到的数据是,只取第一时间出现的accountname列表,结果如下
accountname         date
        a                   07-5-1
        b                   07-5-2
        c                   07-5-8

这条语句如何写?

------解决方案--------------------
select *
from 表名 AS T
where [date]=(select top 1 [Date] from 表名 where accountname = T.accountname )
------解决方案--------------------
select accountname,min(date) as date from 表 group by accountname
------解决方案--------------------

select * from 表 a where not exists (select 1 from 表 where a.accountname=accountname and a.date> date)

个人喜欢用exists