在 MySQL 报告中格式化漏斗报告的数据
Formating data for Funnel Report in MySQL Report
我正在寻找一种方法来为漏斗可视化创建 MySQL 报告。
所以我的输入是一个询问项目的查询。像项目 ID 123456
FROM projects WHERE ID = 123456
结果:
+---------+--------+-----+----------+------+
| Project | Income | Tax | Payments | Rent |
+---------+--------+-----+----------+------+
| 123456 | 2500 | 50 | 250 | 350 |
+---------+--------+-----+----------+------+
对于漏斗,我需要这样的报告:
+------+----------+-------+
| Step | Name | Value |
+------+----------+-------+
| 1 | Income | 2500 |
| 2 | Tax | 50 |
| 3 | Payments | 250 |
| 4 | Rent | 350 |
+------+----------+-------+
是否有 SQL 方法将我的查询内容放入新列(步骤、名称、值)。
谢谢
您可以使用 union all
来反转您的 table:
select *
fom (
select 1 step, 'Income' name, Income value from projects where project = 123456
union all select 2, 'Tax', Tax from projects where project = 123456
union all select 3, 'Payments', Payments from projects where project = 123456
union all select 4, 'Rent', Rent from projects where project = 123456
)
order by step
我正在寻找一种方法来为漏斗可视化创建 MySQL 报告。
所以我的输入是一个询问项目的查询。像项目 ID 123456
FROM projects WHERE ID = 123456
结果:
+---------+--------+-----+----------+------+
| Project | Income | Tax | Payments | Rent |
+---------+--------+-----+----------+------+
| 123456 | 2500 | 50 | 250 | 350 |
+---------+--------+-----+----------+------+
对于漏斗,我需要这样的报告:
+------+----------+-------+
| Step | Name | Value |
+------+----------+-------+
| 1 | Income | 2500 |
| 2 | Tax | 50 |
| 3 | Payments | 250 |
| 4 | Rent | 350 |
+------+----------+-------+
是否有 SQL 方法将我的查询内容放入新列(步骤、名称、值)。
谢谢
您可以使用 union all
来反转您的 table:
select *
fom (
select 1 step, 'Income' name, Income value from projects where project = 123456
union all select 2, 'Tax', Tax from projects where project = 123456
union all select 3, 'Payments', Payments from projects where project = 123456
union all select 4, 'Rent', Rent from projects where project = 123456
)
order by step