Re: [SQL ] Order By 字串?

看板Database作者 (-858993460)時間13年前 (2010/12/12 08:16), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《averywu (看文不要只會用橫的看)》之銘言: : 有沒有可能讓 Order By 依字串來排序呢? : 例: Select Name from Telbook Order By Firstname = '黃'; : 有可能嗎? : 註:SELECT Name FROM Telbook ORDER BY CASE : WHEN strpos(firstname,'黃') > 1 : 這行不能跑... 如果你是要選出有"黃"的 ... WHERE `Name` LIKE '%黃%'; 如果是要按"黃"的位置來排 ... ORDER BY LOCATE('黃',`Name`); 還是你要的不是這樣? -- 'You've sort of made up for it tonight,' said Harry. 'Getting the sword. Finishing the Horcrux. Saving my life.' 'That makes me sound a lot cooler then I was,' Ron mumbled. 'Stuff like that always sounds cooler then it really was,' said Harry. 'I've been trying to tell you that for years.' -- Harry Potter and the Deathly Hollows, P.308 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.28.92

12/12 09:46, , 1F
感謝您。這個ORDER BY LOCATE() 真好用
12/12 09:46, 1F

12/12 13:16, , 2F
其實 locate 是從這裡翻到的: http://tinyurl.com/7e7ve
12/12 13:16, 2F
文章代碼(AID): #1D11HAWY (Database)
文章代碼(AID): #1D11HAWY (Database)