MySQL行转列

IF(expr1,expr2,expr3)

如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。IF() 的返回值为数字值或字符串值


SET @sql = NULL; SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'MAX(IF(c.label = ''',
c.label,
''', c.value, 0)) AS ''',
c.label, ''''
)
) INTO @sql
FROM table_name c; SET @sql = CONCAT('Select phone, ', @sql,
' From table_name c');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
上一篇:Javascript之图片上传预览


下一篇:本站上线KMS服务~一句命令激活windows和office