MySQL group_concat()按case语句值排序
技术问答
210 人阅读
|
0 人回复
|
2023-09-12
|
在一个MySQLgroup_concat()在句子中,我试图对case语句的结果值进行排序。以下查询配置things.name在同一上下文中正确排序,但不排序非美国或未知值。
- T1 D" n6 E, w B2 P3 BSELECT things.id ,group_concat(DISTINCT CASE WHEN things.name 'United States' THEN 'Non-US' WHEN things.name IS NULL THEN 'Unknown' ELSE things.name END ORDER BY name SEPARATOR ',')FROM thingsGROUP BY things.id我想做这样的事,但不起作用:* R. k8 r G; ?9 g
SELECT things.id ,group_concat(DISTINCT (CASE WHEN things.name 'United States' THEN 'Non-US' WHEN things.name IS NULL THEN 'Unknown' ELSE things.name END) AS new_name ORDER BY new_name SEPARATOR ',')FROM thingsGROUP BY things.id有没有办法通过 new_name不使用子查询/嵌套查询进行排序?* m/ Z' g [: d* V Y4 b
% g) N0 q: S. r 解决方案: |
|
|
|
|
|