2011-11-05 116 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 

是你在问什么?我没有得到那里的“订购”栏目。