Re: [SQL ] 關於排序
std_case 原本是 enum('流失','試聽','詢問','班內') 嗎?
可以在不用變更原始資料關聯架構下, 新建一個表, 專為std_case排序用.
std_case_order_table
id,name,order_idx
1,'流失',4
2,'試聽',3
3,'詢問',2
4,'班內',1
查詢時用left join引入這個表, 即可達到排序的目的:
select *
from students
left join std_case_order_table as scot on scot.name=students.std_case
order by scot.order_idx
※ 引述《sdallan ()》之銘言:
: 使用 mysql
: std_case , std_name , std_sch
: 狀況 學校 姓名
: ───────────────
: 流失 高雄 測試
: 試聽 台中 測試
: 詢問 台北 測試
: 班內 新竹 測試
: 想要排序 狀況這個欄位 @@"
: desc asc 兩種下去排都不是我要的。
: 我希望的排法是 班內>詢問>試聽>流失
: 至於學校、姓名,怎麼排,不重要XD
: 還請麻煩幫忙解決
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.104.190.247
推
05/16 19:41, , 1F
05/16 19:41, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 7 篇):