表a
  
  用户编码,用户名称,录入时间      指数
   
    001     a         2010-11-01     10
    001     a         2010-12-01     15
    001     a         2011-01-01     100
    002     b         2010-11-01     2
    002     b         2010-12-01     15
    002     b         2011-01-01     32表 b
  用户编码   金额
   001       100
   002       50
   003       12查询结果
  用户编码  用户名称  金额    指数 
   001       a        100     100
   002       b         50     32。 

解决方案 »

  1.   

    select tA.用户编码,tA.用户名称,表B.金额,tA.指数 from(
    select * from 表A a    
    where not exists (select 1 from 表A where a.用户编码 = 用户编码 and 录入时间> a.录入时间)
    )tA inner join 表b
    where tA.用户编 = 表B.用户编
      

  2.   


    select x.用户编码,x.用户名称,b.金额,a.指数 
    from 
    (select 用户编码,用户名称,max(指数) from a group by 用户编码,用户名称)x,b
    where x.用户编码=b.用户编码
      

  3.   

    写错了select x.用户编码,x.用户名称,b.金额,x.指数 
    from 
    (select 用户编码,用户名称,max(指数) 指数 from a group by 用户编码,用户名称)x,b
    where x.用户编码=b.用户编码
      

  4.   

    select tA.用户编码,tA.用户名称,表B.金额,max(A.指数)
    from 表A a,  表b b
    where tA.用户编 = 表B.用户编
      

  5.   

    写错了
    select tA.用户编码,tA.用户名称,表B.金额,max(A.指数)
    from 表A a, 表b b
    where tA.用户编 = 表B.用户编
    group by  tA.用户编码,tA.用户名称,表B.金额
      

  6.   

    SELECT A.[用户编码],A.[用户名称],B.[金额],MAX(A.[指数]) [指数]
    FROM [表A] A LEFT JOIN [表B] B ON A.[用户编号]=B.[用户编号]
    GROUP BY A.[用户编码],A.[用户名称],B.[金额]
      

  7.   


    if object_id('TableA') is not null
       drop table TableA
    go
    create table TableA
    (
     用户编码 varchar(10),
     用户名称 varchar(10),
     录入时间 varchar(10),
     指数  int
    )
    go
    insert into TableA
    select '001','a','2010-11-01',10 union all
    select '001','a','2010-12-01',15 union all
    select '001','a','2011-01-01',100 union all
    select '002','b','2010-11-01',2 union all
    select '002','b','2010-12-01',15 union all
    select '002','b','2011-01-01',32
    goif object_id('TableB') is not null
       drop table TableB
    go
    create table TableB
    (
     用户编码 varchar(10),
     金额 int
    )
    go
    insert into TableB
    select '001',100 union all
    select '002',50
    goselect b.用户编码,用户名称,金额,指数 from TableB b Left Join (select * from TableA a where not exists(select 1 from TableA where 指数>a.指数 and 用户编码=a.用户编码)) c on b.用户编码=c.用户编码