嗨,我有一张看起来像这样的桌子
dt ticker open
1 A 1
1 B 3
2 A 1.1
2 B 2.5
我需要结果看起来像
dt A B
1 1 3
2 1.1 2.5
我在下面包含的当前查询让我
dt A B
1 1 NULL
1 NULL 3
2 1.1 NULL
2 NULL 2.5
如果有人可以帮助我,将不胜感激
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'(IF(ticker = ''',
ticker,
''', open, NULL)) AS ''',
ticker,''''
)
) INTO @sql
FROM
prices;
SET @sql = CONCAT('SELECT dt, ', @sql, ' FROM prices');
-- SET @sql = CONCAT('SELECT dt, ', @sql, ' FROM prices GROUP BY dt');
PREPARE stmt FROM @sql;
EXECUTE stmt;