Sql server 2012 从多个列中获取1行

Sql server 2012 从多个列中获取1行,sql-server-2012,pivot,Sql Server 2012,Pivot,我有两张桌子 表1:订单 表2:详细信息 所需输出: orderid unitid jan feb mar apr may jun ......... dec 1 aa yes yes 3 cc yes yes yes yes 对于活动为1的所有订单和所有UnitId 我试着使用case语句,一个orderid有多行,这

我有两张桌子

表1:订单

表2:详细信息

所需输出:

orderid   unitid     jan   feb  mar  apr  may  jun  .........  dec
  1           aa                               yes             yes
  3           cc     yes   yes  yes  yes
对于活动为1的所有订单和所有UnitId

我试着使用case语句,一个orderid有多行,这不是我想要的


我看到了很多使用一个表的pivot示例,如何使用两个表来实现这一点?我正在使用SQL Server 2012。

可能是Select as参数中的Select

像这样的东西

Select orderid, unitid, (SELECT month 
                         From Table2 
                         WHERE ...)
From table1
Where ...
我对这个问题的回答是:


您好,“SQL 2012”是指SQL Server 2012吗?为什么它被贴上了甲骨文的标签?如果不是,这意味着什么?如果你能把你的问题包括到目前为止你已经尝试过的东西,那就太好了。谢谢要使用两个表,只需编写一个联接并透视结果。嗨,Ben,谢谢你的反馈。我已经编辑了文本。
orderid   unitid     jan   feb  mar  apr  may  jun  .........  dec
  1           aa                               yes             yes
  3           cc     yes   yes  yes  yes
Select orderid, unitid, (SELECT month 
                         From Table2 
                         WHERE ...)
From table1
Where ...