2013-02-28 90 views
0

在SQL Server中,是否有机会显示3个表的结果? (其实4)从3个表中获取记录

第4张表包含1列与其他类似。其他3个表的相似列的值是不同的。换句话说,如果您在第4列表格中选择'1',则应该显示第1个表格的结果,如果您选择'2',第2个等...

+1

您可以添加一些布局示例四张桌子? – 2013-02-28 03:36:26

+0

谢谢你的回复。我有一个想法去做。 – 2013-02-28 03:53:16

回答

0
select fourth.pk, 
case fourth.columnx 
when '1' then one.columnx 
when '2' then two.columnx 
when '3' then three.columnx 
else 'Exception to the rule?' 
end as 'Column A' 
from fourth 
join one on fourth.joinid=one.joinid 
join two on fourth.joinid=two.joinid 
join three on fourth.joinid=three.joinid