How do I select two most nearly fields to specific timestamp?
SELECT *
FROM 'wp_weather'
WHERE ( timestamp most nearly to 1385435000) AND city = 'Махачкала'
The table:
id | timestamp
---------------
0 | 1385410000
1 | 1385420000
2 | 1385430000
3 | 1385440000
4 | 1385450000
SELECT *
FROM wp_weather
WHERE city = 'Махачкала'
order by abs(timestamp - 1385435000)
limit 2
You may try like this:
SELECT * FROM 'wp_weather'
WHERE city = 'Махачкала'
order by abs(timestamp - 1385435000)
limit 2
Also check the ABS function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With