输入
+---------+--------------------+-----------+
| id | reason | location |
+---------+--------------------+-----------+
| 1077501 | credit_card | AZ |
| 1077430 | car | GA |
| 1077175 | small_business | IL |
| 1076863 | other | CA |
| 1075358 | other | OR |
| 1075269 | wedding | AZ |
| 1069639 | debt_consolidation | NC |
| 1072053 | car | CA |
| 1071795 | small_busines | CA |
+---------+--------------------+-----------+
输出应为
+----------+-------------+-----+----------------+----------+---------+-------+
| location | credit_card | car | small_business | other... | wedding | total |
+----------+-------------+-----+----------------+----------+---------+-------+
| AZ | 1 | 0 | 0 | 0 | 1 | 2 |
| CA | 0 | 1 | 1 | 0 | 0 | 2 |
+----------+-------------+-----+----------------+----------+---------+-------+
输出应为上述格式,因为每个位置都作为一列。
1条答案
按热度按时间m0rkklqb1#
对动态列使用透视