使用SQL Query检索记录

时间:2012-02-28 09:20:58

标签: mysql sql

我想从包含image_typepriority等字段的表中检索记录。

喜欢

property id image_type priority
1            1          1
1            0          1
1            1          2
1            0          2
1            0          3

我希望显示所有图像类型记录合在一起的记录。根据优先顺序排列ASCDESC

3 个答案:

答案 0 :(得分:1)

SELECT 
   *
FROM 
   undefined_table_name
GROUP BY 
   image_type 
ORDER BY
   image_type ASC;

答案 1 :(得分:0)

使用ORDER BY

SELECT `property id`, `image_type`, `priority`
FROM `your_table`
ORDER BY `image_type`, `priority` DESC

答案 2 :(得分:0)

你希望它们按priority(ASC)排序,然后按image_type(DESC)排序,所以你会这样做:

SELECT `property id`, `image_type`, `priority`
FROM `your_table`
ORDER BY `priority`, `image_type` DESC
相关问题