2

我有更多表要交叉加入它们,并且我想显示每个表的字段如下:

tb1.filed1 tb1.filed2 tb2.filed1 .....

我应该怎么办?我如何选择具有详细信息的字段,例如表名。

谢谢....

4

2 回答 2

4

最简单的方法是使用列别名,就像你给它另一个名字一样:

Select 
   tb1.filed1 as 'tb1.filed1', 
   tb1.filed2 as 'tb1.filed2', ... //continue for all your coumns
From table1 tb1
Inner Join table2 tb2 on [your criteria]

但是,我建议您使用更具描述性的名称。也许像

Select 
  tb1.filed1 as 'RawInitialFiledDate', 
  tb1.filed2 as 'RawReFileDate',
  tb2.filed1 as 'ConfirmedInitialFiledDate', 
  tb2.filed2 as 'ConfirmedReFileDate'
from table1 tb1
Inner join table2 tb2...
于 2010-08-16T13:50:44.180 回答
1

使用别名给出有意义的描述......例如

select 
   tb1.field1 as "Order ID",
   tb1.field2 as "Order Date", 
   tb2.field1 as "Product ID"
   -- ,etc    
 from Orders tb1
 inner join OrderProducts tb2 on 
    tb2.OrderID = tb1.OrderID and
    tb1.OrderID = @OrderID
于 2010-08-16T13:49:09.800 回答