I've been trying to resolve this for about three days and found the answer nowhere.
I have a table in the database where I need to do a SELECT on all products but they need to be sorted according to the average between date X and date X, a basic example of the table I made quickly
SELECTS and GROUPS are working, it's just the ORDER that I can not solve, one of several queries that I tried unsuccessfully to organize the rows:
SELECT product, time, date FROM graficos
ORDER BY time HAVING (date BETWEEN 2017-02-20 AND 2017-02-23) DESC
Example well summarized in more detail (the original table is too big to paste here):
-------------------------------
PRODUCT | TIME | DATE |
Bombom | 35 | 2017-02-15 |
Gato | 25 | 2017-02-20 |
Pizza | 28 | 2017-02-23 |
-------------------------------
Output:
-------------------------------
Pizza | 28 | 2017-02-23 |
Gato | 25 | 2017-02-20 |
Bombom | 0 | 2017-02-15 |
-------------------------------