gpt4 book ai didi

mysql - 我可以通过 group_by 分成几列吗

转载 作者:行者123 更新时间:2023-11-29 06:50:34 25 4
gpt4 key购买 nike

+---------+-------+----------+
| number | type | price |
+---------+-------+----------+
| 1 | A | 7.00 |
| 1 | B | 3.00 |
| 2 | A | 1.00 |
| 2 | B | 2.00 |
| 3 | A | 6.00 |
| 3 | B | 9.00 |
+---------+-------+----------+

如果我有一个像上面的示例表一样的表。是否可以运行一个查询来生成类似于下面示例的 mysql 表格?

+---------+---------+----------+
| number | A | B |
+---------+---------+----------+
| 1 | 7.00 | 3.00 |
| 2 | 1.00 | 2.00 |
| 3 | 6.00 | 9.00 |
+---------+---------+----------+

最佳答案

select number,
min(case when `type` = 'A' then price end) as A,
min(case when `type` = 'B' then price end) as B
from your_table
group by number

关于mysql - 我可以通过 group_by 分成几列吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47663394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com