非遞迴無限分類的,有關問題,請下

來源:互聯網
上載者:User
非遞迴無限分類的,問題,請高手指點下
本帖最後由 vbker 於 2012-09-05 10:19:59 編輯

資料庫欄位如下,暫時以地區代表欄目,cid為欄目ID,category為欄目名,chain為關係樹,rank為欄目排序

mysql> select * from mc_category;
+-----+----------+--------------+------+
| cid | category | chain | rank |
+-----+----------+--------------+------+
| 1 | 國內 | 0_1 | 2 |
| 2 | 國外 | 0_2 | 1 |
| 3 | 華北 | 0_1_3 | 2 |
| 4 | 東北 | 0_1_4 | 1 |
| 5 | 西部 | 0_1_5 | 3 |
| 6 | 河南 | 0_1_3_6 | 1 |
| 7 | 鄭州 | 0_1_3_6_7 | 2 |
| 8 | 鞏義 | 0_1_3_6_7_8 | 1 |
| 9 | 洛陽 | 0_1_3_6_9 | 1 |
| 10 | 偃師 | 0_1_3_6_9_10 | 1 |
| 11 | 遼寧 | 0_1_4 | 3 |
| 12 | 吉林 | 0_1_4_11_12 | 1 |
| 13 | 上街 | 0_1_3_6_7_13 | 2 |
+-----+----------+--------------+------+


使用
select category,chain from mc_category group by chain order by chain;

可以按照正確的父子關係列出分類樹,但是我現在還需要讓同級的欄目按照rank值進行排序,這個用mysql可以做到嗎?




======================================================================

分享到:
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.