首先,我们会计算æ¯ä»¶å•†å“的总票数,并按product_id
进行分组。然åŽï¼Œæˆ‘们会获å–issue
列的值以åŠæ¯ä¸ªåˆ—的出现次数。已ç»åœ¨å°æç´ä¸è¯æ˜Žäº†è¿™ä¸€ç‚¹ã€‚
我需è¦çš„是能够按æ¯ä¸ªé—®é¢˜çš„出现次数排åºã€‚例如,我们希望按broken-part
或not-received
的最高数é‡çš„产å“进行排åºï¼Œä»¥ä¾¿æŒ‰issue
列的值排åºå¹¶æŒ‰å¤šå°‘次排åºæ¯ä¸ªäº§å“都å˜åœ¨è¯¥é—®é¢˜ã€‚
谢谢ï¼
ç”案 0 :(得分:1)
您å¯ä»¥ä½¿ç”¨æ¡ä»¶æ€»å’Œã€‚
例如
SUM(CASE WHEN `issue` = 'missing-part' THEN `count` ELSE NULL END) missing_part_total
然åŽæŒ‰é¡ºåºæŽ’åºã€‚
ç”案 1 :(得分:0)
GROUP_CONCAT()
采用ORDER BY
å‚数:
SELECT d2.product_id, t.title,
SUM(`count`) AS total_issues,
GROUP_CONCAT(`issue`, ':', `count` ORDER BY `count` DESC SEPARATOR ',') AS issues
注æ„:ä¸è¦å¯¹åˆ—å使用å•å¼•å·ã€‚åªéœ€å¯¹å—符串和日期常é‡ä½¿ç”¨å•å¼•å·ã€‚