After performing a query, I have a table like this:
| Date | Mode | Count |
|---|---|---|
| 2022-12-20 | A | 1 |
| 2022-12-20 | B | 11 |
| 2022-12-20 | C | 8 |
| 2022-12-21 | A | 10 |
| 2022-12-21 | C | 4 |
| 2022-12-22 | A | 100 |
| 2022-12-22 | B | 48 |
| 2022-12-22 | C | 81 |
It shows, for each day, the count of each of the different modes. If a certain mode is 0, it’s not in the table.
I’m using dynamic queries to get the data, and I want to LIMIT the quantity that it’s returned.
For example, if I limited it to two days, I would want to get only this:
| Date | Mode | Count |
|---|---|---|
| 2022-12-20 | A | 1 |
| 2022-12-20 | B | 11 |
| 2022-12-20 | C | 8 |
| 2022-12-21 | A | 10 |
| 2022-12-21 | C | 4 |
i.e., all the rows with the first two days.
How can I do it?
EDIT I have a REST API developed using Spring Boot / JPA. I’m sending a parameterised query through the server – and I only have the initial date and the number of days onwards I need to filter. I now see that I can find a way to simply send the query using a BETWEEN operator, by doing some calculations before.
>Solution :
Using the between operator:
SELECT * FROM TABLE WHERE DATE BETWEEN '2022-12-20' AND '2021-12-22'