iT邦幫忙

0

mysql資料庫 做簡單排序 求解

以下是我SQL排序方法 但是 我要依照classid ASC排序 不知為何 CALSSID大的會在上面
我的優先順序是 cvdname>cname>classid>cell 相同廠一定顯示再一起 接下來是工程但後面classid就沒有依照我要的排了

SELECT * FROM class where `cell`>0 AND`cdates`='2021-01' group by `ci`,`cin`,`cip` ORDER BY`class`.`cvdname` ASC , `class`.`cname`, `class`.`classid` ASC,`class`.`cell` ASC

顯示結果在下方圖片
https://ithelp.ithome.com.tw/upload/images/20210205/20134470q20BWXTRES.jpg
這不是我預期的結果
我希望最上面的兩項移至classid=206下面 請問有辦法做到嗎 謝謝

看更多先前的討論...收起先前的討論...
原因是cname吧~因為內容第一個字是英文(B工程)~英文>中文
所以英文會被優先排在上面~
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:14:08 檢舉
請問如果不是英文就不會有問題了是嗎
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:15:32 檢舉
我改成中文還是一樣耶
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:19:31 檢舉
我把中文名子改長一點可以了 可是我想要依照classid排序 cname有辦法做到嗎因為我無法控制cname裡的字串筆畫或長度
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:39:20 檢舉
要如何不因為CNAME欄位裡面的資料因為字串長度或筆畫而改變排序呢? 要另外找排序的依據嗎 謝謝
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2021-02-05 11:51:30
最佳解答

試試看

SELECT * FROM class where `cell`>0 AND`cdates`='2021-01' group by `ci`,`cin`,`cip` ORDER BY`class`.`cvdname` ASC , `class`.`classnid`, `class`.`classid` ASC,`class`.`cell` ASC
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 12:46:45 檢舉

大感謝

1
japhenchen
iT邦超人 1 級 ‧ 2021-02-05 11:21:31

ORDER BY `cvdname` ASC , `classid`.`cname`, `class`.`class`.`cell` ASC
看更多先前的回應...收起先前的回應...
yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:29:41 檢舉

1.class.class兩個CALSS?
2.classid怎麼做排序呢
謝謝

yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:36:26 檢舉

我跑出來是這樣
https://ithelp.ithome.com.tw/upload/images/20210205/20134470O9KIaS4gTj.jpg

打錯欄位名,把classnid看成classid惹

ORDER BY `class`.`cvdname` ASC , `class`.`classnid`,`class`.`cname`,`class`.`cell` ASC

MYSQL的繁體中文排序以筆畫排序為預設

yhn2880 iT邦新手 5 級 ‧ 2021-02-05 11:50:27 檢舉

我在試試

yhn2880 iT邦新手 5 級 ‧ 2021-02-05 12:00:20 檢舉

這樣我工程名稱中間會有不一樣的 沒關係 我另外新增欄位判斷了 謝謝

我要發表回答

立即登入回答