我想将 Null 改为 0 并在列和行的末尾添加小计。我该如何改变?
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'sum(case when gameid = ''',
gameid,
''' then score end) AS ''',
gameid, ''''
)
) INTO @sql
FROM scores;
SET @sql = CONCAT('SELECT playerid, ', @sql, '
FROM scores
GROUP BY playerid');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;