以c 表为主, 链接查询。
select c.id,c.name,a.weight,b.value form a right join c left join b
on b.id=c.id
on a.id =c.id
没有测试

解决方案 »

  1.   

    结果中的height 从哪里来的?
      

  2.   

    select
    ID,
    Name,
    [weight]=(select top 1 value from b where c_id=c.ID and a_id=1),
    [height]=(select top 1 value from b where c_id=c.ID and a_id=2)
    from 
      

  3.   


    select id,
    name,
    weight = b.value,
    height = d.value
    from c
    left join (select * from b where a_id = 1) b
    on c.id = b.c_id
    left join (select * from b where a_id = 2) d
    on c.id = d.c_id
      

  4.   

    不好意思,我打错了,最后查询的结果是id,name,weight,type                                                                              1,玩具,10,   小 
    2,食品,,大   
    id是C表的id,其中a表中的记录数未知,我这只列出了两个,可能是更多项,要求是这些项是查询结果的列名。
    对于用width=.......,我不知道是什么,这个width是查A表项才得出的,不能直接写