简体   繁体   中英

I want to ascend and decend MYSQL from a value in the database

I want to ascend MYSQL from a value in the database. Hypothetically: database with table tbl_numbers column numbers has 10 values in it 1-10. I want to:

order by numbers desc {from 8} LIMIT 3

it would show

8
7
6

instead of:

order by numbers desc LIMIT 3 

10
9
8

If this is possible what php and not mysql that's good too.

--update!--

The example I gave was way to easy, I really need to match the date() with the dates of the entry's in the database and start the asend or decend from there any ideas? The date format is in 2010-06-18

ORDER BY numbers DESC
LIMIT 3,3

First argument for limit is (10 entries + 1) - 3; second argument is the number of records to return

Alternatively:

WHERE numbers <= 8
ORDER BY numbers DESC
LIMIT 3

Something along the lines of

ORDER BY (numbers < 8) DESC, numbers DESC LIMIT 3

should do the job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM