原始表 t(center, station),輸出格式:
中心A
服務站1
服務站2
中心B
服務站3
SELECT center, station
FROM (
SELECT DISTINCT center AS c, center, '' AS station FROM t
UNION ALL
SELECT center, '', station FROM t
) d
ORDER BY c, center DESC, station;
station='' 佔位。center 重複以便排序分組。c:僅來自第一個子查詢,確保所有中心標題行排在該中心明細之前;center DESC 使標題行 (station='') 排在明細行前。UNION 快 (不去重),此處業務允許重複中心名。同理可擴展至 3+ 層:每層一個 UNION ALL 子查詢,外層 ORDER BY 疊加排序鍵。