1

我在下面有这个示例表

+---------+----------------------+
| PRODUCT | TYPE                 |
+---------+----------------------+
| WIN 10  | Home                 |
+---------+----------------------+
| WIN 10  | Pro                  |
+---------+----------------------+
| WIN 10  | Pro for Workstations |
+---------+----------------------+
| Linux   | Ubuntu               |
+---------+----------------------+
| Linux   | Red Hat              |
+---------+----------------------+
| Linux   | Fedora               |
+---------+----------------------+

我想使用 MySQL 将其更改(转置)以获得如下所示的结果

+---------+-------------------------------+
| PRODUCT | TYPE                          |
+---------+-------------------------------+
| WIN 10  | Home,Pro,Pro for Workstations |
+---------+-------------------------------+
| Linux   | Ubuntu,Red Hat,Fedora         |
+---------+-------------------------------+

你能帮我解决这个问题吗?我已尝试使用此论坛的所有方法,但无法获得所需的结果,非常感谢您的帮助

4

1 回答 1

0

在 mysql 你可以使用 group_concat

select product, group_concat(type)
from my_table 
group by product 

或订购

select product, group_concat(type order by type)
from my_table 
group by product 

对于 BigSQL,等效函数应该是 LISTAGG(type)

于 2020-06-11T14:39:37.513 回答