我想查询出相同的cuno列对应的cadt列中其最小的值,
需求说明:账号表中有客户,账号和账号创建日期三个字段;其中一个客户下有许多账号,现在想查询出所有客户的创建日期;即它所属的账号的创建日期中最先的一个即为客户创建日期。查询语句
客户    账号      账号创建日期
cuno     cano             cadt
001     afasdfasdf      20110101
001     dfdsddfifp      20120201
002     sergsfdsfs       20100101
002    wqdfsdfdf      20110101
003    ueoeijfadf      20100101
003     fyadssvvdf      20110101
003    fiadafasdf     20120201得到的结果应该是:
001     afasdfasdf      20110101
002     sergsfdsfs       20100101
003    ueoeijfadf      20100101

解决方案 »

  1.   

    select * from tb as t
    where not exists(select 1 from tb where 客户=t.客户 and 创建日期<t.创建日期)
      

  2.   

    select  *  from  T a where exists (select cuno ,min(cadt)
      from T  group by cuno where a.cuno =cuno)
      

  3.   

    --0r
    select * from tb as t
    where 创建日期=(select min(创建日期) from tb where 客户=t.客户 )
      

  4.   


    select cuno,cano,cadt from tb t
    where cadt=(select min(cadt) from tb where cuno=t.cuno )
    --orselect * from tb  t
    where not exists(select 1 from tb where cuno=t.cuno  and cadt<t.cadt )