我有个问题:
SELECT
count(*), `merchant_id`, `merchant_finance_id`, `merchant_channel_id`, `status`
FROM `application`
WHERE `created_at` >= '2018-04-30' AND `created_at` < '2018-05-01'
GROUP BY `merchant_id`, `merchant_finance_id`, `merchant_channel_id`, `status`
结果如下:
-------------------------------------------------------------------------------
| count(*) | merchant_id | merchant_finance_id | merchant_channel_id | status |
-------------------------------------------------------------------------------
| 2 | D8E2459CD78C | 55E4D520AC1C | 66A1861918C5 | ACCEPTED |
| 2 | D8E2459CD78C | 55E4D520AC1C | 66A1861918C5 | REFERRED |
| 1 | E50E50212627 | 6F8F15729DA7 | E02ACD64B452 | AWAITING-ACTIVATION |
| 2 | E50E50212627 | 6F8F15729DA7 | E02ACD64B452 | DEPOSIT-PAID |
| 1 | E50E50212627 | 6F8F15729DA7 | E02ACD64B452 | READY |
| 1 | E50E50212627 | 6F8F15729DA7 | E02ACD64B452 | REFERRED |
| 1 | F04FBD7AEB30 | C11CBD2FC1F8 | 21F2D435EA9D | AWAITING-ACTIVATION |
-------------------------------------------------------------------------------
但是有什么办法我可以安排 status
改成子列?如:
-------------------------------------------------------------------------------
| count(*) | merchant_id | merchant_finance_id | merchant_channel_id | accepted | referred | awaiting_activation | deposit_paid | ready
-------------------------------------------------------------------------------
| 2 | D8E2459CD78C | 55E4D520AC1C | 66A1861918C5 | 2 | 2 | 0 | 0 | 0 |
| 5 | E50E50212627 | 6F8F15729DA7 | E02ACD64B452 | 0 | 1 | 1 | 2 | 1 |
| 1 | F04FBD7AEB30 | C11CBD2FC1F8 | 21F2D435EA9D | 0 | 0 | 1 | 0 | 0 |
-------------------------------------------------------------------------------
注:
有一个已定义的不同 status
类型-所以我不必担心“布拉布拉赫”是一种身份类型。
1条答案
按热度按时间fquxozlt1#
您可以尝试使用条件聚合函数,如果您使用
Mysql
你可以这样做。测试DLL
查询1:
结果: