我有一个如下所示的表格:
Name | Type
Maurice | Gold
Lisa | Gold
Andrew | Silver
Matthew | Platinum
Sarah | Gold
Peter | Platinum
Franco | Platinum
Patrick | Silver
我一直在尝试使用“选择”来按类型分组显示它们,但我还没有找到任何正确的方法。我正在寻找的结果是这样的:
Silver | Gold | Platinum
Andrew | Maurice | Matthew
Patrick | Lisa | Peter
NULL | Sarah | Franco
有没有办法让结果看起来像这样?谢谢!
最佳答案
select (case when type='Silver' then name end) as silver,
(case when type='Gold' then name end) as gold,
(case when type='Platinum' then name end) as platinum
from table_name
关于mysql - 使用 "SELECT"显示分组结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38766342/