[英]Pivot column to row in mysql result output
I have the following result 我有以下结果
A B C
1 2 3
How do I get the result like 我如何得到像
title1 title2
A 1
B 2
C 3
My query is something like this 我的查询是这样的
select
sum(if(d =4,1,0)) AS 'A',
sum(if(d = 4 and (datediff(curdate(), r_date)=1),1,0)) AS ' B',
sum(if(d = 1 and (datediff(curdate(), r_date)=2),1,0)) AS ' C'
from delay ;
It appears that you are trying to unpivot a table in MySQL. 看来您正在尝试取消MySQL中的表格。 One way to do this would be to use a series of unions: 一种方法是使用一系列联合:
SELECT 'A' AS title1, A AS title2
FROM delay
UNION ALL
SELECT 'B' AS title1, B AS title2
FROM delay
UNION ALL
SELECT 'C' AS title1, C AS title2
FROM delay
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.