select a.id,a.name,b.id,min(b.money) as money
from A,B
where a.id = b.id and (b.money is not null)
group by a.id,a.name,b.id

解决方案 »

  1.   

    --下面是数据测试--创建数据测试环境
    declare @tb1 table(id int,name varchar(2))
    insert into @tb1
    select 1,'bb'
    union all select 1,'bb'
    union all select 2,'cc'
    declare @tb2 table(id int,money int)
    insert into @tb2
    select 1,20
    union all select 1,40
    union all select 2,60
    --得到结果
    select a.id,a.name,b.id,min(b.money) as money
    from @tb1 a,@tb2 b
    where a.id = b.id and (b.money is not null)
    group by a.id,a.name,b.id
      

  2.   

    select min(a.id),a.name,b.id,b.money from A a,B b where a.id = b.id and b.money is not null
      

  3.   

    select top 1 a.id,a.name,b.id,b.money1 from A a,B b where a.id=b.id and b.money1 is not null
      

  4.   

    select distinct a.id,a.name,b.id from A a,B b where a.id = b.id and b.money is not null