SQL按查询排序

时间:2015-02-17 00:55:58

标签: mysql sql

我有以下SQL语句

SELECT 
      x_category.id, 
      x_category.name, 
      x_category.parent
FROM x_listings, x_category
WHERE x_listings.status = 1 
AND 
   (x_listings.cat_1_id = x_category.id OR
    x_listings.cat_2_id = x_category.id OR 
    x_listings.cat_3_id = x_category.id) 
GROUP BY x_category.id
ORDER BY x_category.id, x_category.parent  

返回:

id, name, parent
1, Toys, 0
2, Clothes, 0
3, Hardware, 0
4, Educational Toys, 1
5, Women's Clothes, 2
6, Men's Clothes, 2
7, Hammers, 3

但是,我希望结果按此顺序返回:

id, name, parent
1, Toys, 0
4, Educational Toys, 1
2, Clothes, 0
5, Women's Clothes, 2
6, Men's Clothes, 2
3, Hardware, 0
7, Hammers, 3

如何修改SQL语句来实现这一目标?

由于

0 个答案:

没有答案