2011-11-05 82 views
-1
id  product_cat_id  product_type_id   ordering 
1   1     1      1 
2   2     3      1 
3   1     2      1 
4   1     1      2 
5   3     1      1 

我想按照product_cat_id的順序,然後從訂購欄中輸入product_type_id。輸出應該是這樣的:sql訂購colums查詢

id  product_cat_id  product_type_id   ordering 
1   1     1      1 
4   1     1      2 
3   1     2      1 
2   2     3      1 
5   3     1      1 
+2

這真是基本的sql。你花了超過2秒研究這個? – regality

+0

我做了,但我想不出如何分階段我的谷歌搜索,這就是爲什麼我不得不舉一個堆棧溢出的例子。這個問題真的值得大拇指嗎? – milan

回答

3

使用ORDER BY修飾符。您可以將以逗號分隔的多個字段串起來。

例:

SELECT id, product_cat_id, product_type_id, ordering FROM table ORDER BY product_cat_id, product_type_id, ordering 

這將通過產品CAT_ID排序,然後product_type_id,然後訂購。

祝你好運:)

+0

謝謝!這正是我想要的!我需要等10分鐘才能接受你的答案 – milan

0

這個添加到查詢:

order by product_cat_id, product_type_id 

是你在問什麼?我沒有得到那裏的「訂購」欄目。