So i have an table with daily information of different accounts, a user wants to get the data of all accounts based on an date xxxx-xx-xx, but the latest information in some of these accounts are from some days earlier than the date the user want. How can i make an query that gets the information from the date the user want and also info that have the most close date from what he want. I hope i made myself clear, the database is in mysql.
EDIT:
bit more of explanation
SELECT * from `table` where date BETWEEN '2021-01-01' AND userinput
so the objective is make this query get the latest information, the one closest to the userinput, given the fact that there's multiple rows of the same account but with different dates, the only ones that matters are the ones closer to the date the user has given.
EDIT 2:
TABLE accounts:
id | account_id | account_info | date |
---|---|---|---|
1 | 15 | some info 1 | 2020-01-01 |
2 | 15 | some info 2 | 2020-01-02 |
3 | 15 | some info 3 | 2020-01-03 |
4 | 16 | some info 4 | 2020-01-03 |
5 | 17 | some info 1 | 2020-01-07 |
the table above shows in an simplified way how the table looks like, the user them wants to take the information of every account on the day 7 let's suppose, as we can see account 15 as info only until day 3, account 16 the same, only account 17 have info on day 7, so the query must get the info of account 15 and 16 only from day 3 (because in this case day 3 is the closest to day 7) while for account 17 from day 7.
SELECT * from accounts --> what's next? i have the user input [2021-01-07]