开发者

Ordering and grouping MySQL data

+----+------------------+-----------------+
| id | template_type_id | url             |
+----+------------------+-----------------+
|  1 |       1          | text            |
|  2 |       2          | text            |
|  3 |       1          | text            |
|  4 |       1          | text            |
|  5 |       1          | text            开发者_如何学编程|
|  6 |       1          | text            |
|  7 |       1          | text            |
|  8 |       1          | text            |
|  9 |       2          | text            |
| 10 |       2          | text            |
+----+------------------+-----------------+

As i am using 1 page template and 2 page template i need to reorder above result as per 1 page and 2 page as below:

+----+------------------+-----------------+
| id | template_type_id | url             |
+----+------------------+-----------------+
|  1 |       1          | text            |
|  3 |       1          | text            |
|  2 |       2          | text            |
|  4 |       1          | text            |
|  5 |       1          | text            |
|  6 |       1          | text            |
|  7 |       1          | text            |
|  9 |       2          | text            |
| 10 |       2          | text            |
|  8 |       1          | text            |
+----+------------------+-----------------+
+------------------------------------------+
   ----------------  ------------------
   |               | |                 |
   |               | |                 |
   |               | |                 |
   |               | |                 |
 
   |               | |                 |
   |               | |                 |
   |               | |                 |
   |               | |                 |
   |               | |                 |
   ----------------  ------------------
+------------------------------------------+


Assuming there's publish_date column in the table that is not shown and the values in it consistent with the ordering of the records in the examples 1 and 2, I suggest:

order by publish_date, template_type_id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜