好的,所以目前我使用的是一个比使用多个连接更有效的数据透视表。
目前看起来像这样......
SELECT * FROM
(
SELECT
s.stock_code , sui.field_value, su.field_index
FROM stock_uda as SU
INNER JOIN stock_uda_item as SUI ON SU.field_index = SUI.field_index
INNER JOIN stock as S ON S.stock_id = SUI.stock_id
WHERE sui.field_value != ''
) as A
PIVOT
(
MAX (Field_value)
FOR Field_index in ("846164","846165","846166","848267","945290","945291","1123994","1062208","846169","846170","846171","846172","846173","846174")
) AS MyPivotData
IN 语句中的数字字符串可以更改。 我可以通过运行以下代码来检索这些代码......
SELECT field_index
FROM stock_uda
我已经尝试过分配这些并创建一个字符串,然后我在我的枢轴IN语句中使用但是没有运气。
任何指针都会很棒!