问题
I have a simple question. In MySQL, consider a row "n", how can we order rows by id (for example), but start from the row "n+1" and end to the row "n-1" ?
Thanks !
EDIT : I ommit to precise that I seek the query in MySQL.
From an answer below, here an example :
ID
---
1
2
3
4 <--N
5
6
I want Desired Results ordered as follows
5 <--N + 1
6
1
2
3 <--N - 1
回答1:
So you mean. For a table
ID
---
1
2
3
4 <--N
5
6
You want Desired Results ordered as follows?
5 <--N + 1
6
1
2
3 <--N - 1
If so
SELECT ID
FROM T
WHERE ID <> 4
ORDER BY CASE WHEN ID > 4 THEN 0 ELSE 1 END, ID
回答2:
Assuming table MyTable
with integer column N
:
SELECT *
from MyTable
where Id between N-1 and N+1
order by N desc
回答3:
You're asking how to sort by descending ?
Just stick
ORDER BY col a , col b DESC;
at the end
来源:https://stackoverflow.com/questions/17114876/sql-ordering-data-from-row-n1-to-n-1