-------注意sum函数 是统计合-------
select name,
sum(case when course='java' then grade end) as java,
sum(case when course='C++' then grade end) as C++,
sum(case when course='C#' then grade end) as C#
from test group by name
---------------------如果有字符串 就单纯的 转换用合并函数合一下 不然group by 只显示第一条------------------------------
SELECT * FROM(SELECT `name`,
GROUP_CONCAT(CASE WHEN `key`='redis.host' THEN val END SEPARATOR ',') AS `host`,
GROUP_CONCAT(CASE WHEN `key`='redis.port' THEN val END SEPARATOR ',')AS `port`,
GROUP_CONCAT(CASE WHEN `key`='redis.database' THEN val END SEPARATOR ',')AS `database`,
GROUP_CONCAT(CASE WHEN `key`='redis.pwd' THEN val END SEPARATOR ',' )AS `pwd`
FROM `sys_game_config` WHERE `name` = 'cache-1069' )a GROUP BY `name`