Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何基于SQL Server中的数据元素类别创建属性?_Sql Server - Fatal编程技术网

Sql server 如何基于SQL Server中的数据元素类别创建属性?

Sql server 如何基于SQL Server中的数据元素类别创建属性?,sql-server,Sql Server,我想将下表转换为SQLServer中的交叉表。我是否必须使用Pivot方法或CASE语句来获得所需的输出 输入- 输出- 到目前为止,我已经尝试了以下代码- TRANSFORM [PODB].[Model] SELECT [PODB].[PO], [PODB].[Color] FROM PODB GROUP BY [PODB].[PO], [PODB].[Color], [PODB].[Model] PIVOT [PODB].[Car Make]; 但是它没有给出确切的输出。您可以使用ca

我想将下表转换为SQLServer中的交叉表。我是否必须使用Pivot方法或CASE语句来获得所需的输出

输入-

输出-

到目前为止,我已经尝试了以下代码-

TRANSFORM [PODB].[Model]
SELECT [PODB].[PO], [PODB].[Color]
FROM PODB
GROUP BY [PODB].[PO], [PODB].[Color], [PODB].[Model]
PIVOT [PODB].[Car Make];

但是它没有给出确切的输出。

您可以使用
case
表达式进行条件聚合:

select po, color, 
       isnull(max(case when [Car Make] = 'toyota' then model end), 'N/A') as toyota,
       . . .
       isnull(max(case when [Car Make] = 'hyundai' then model end), 'N/A') as hyundai
from podb p
group by po, color;