以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
没有测试
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
没有测试
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
c
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
2,食品,,大
id是C表的id,其中a表中的记录数未知,我这只列出了两个,可能是更多项,要求是这些项是查询结果的列名。
对于用width=.......,我不知道是什么,这个width是查A表项才得出的,不能直接写