3
I want to make an SQL query ordered for the first 3 months from the current month, example:
Current month is August (08), so I order as:
10
9
8
1
12
I’m using the following command:
SELECT * FROM `tb_convencao` WHERE `lg_historico` = 0 ORDER BY (`desc_database`) >= MONTH(now()) DESC, (`desc_database`) < date_add(MONTH(now()), interval 3 month)
But it’s returned to me:
10
12
8
9
1
Any hint?
The question makes no sense. What is commanded for the last three months? Ordination has no condition. Give more information on how the table is composed, the content and expected result, and better explain the objective. The order should be by which column? Or does it not even need order? Should there be a filter that only takes the lines from the last 3 months? What types of columns?
– Maniero
The field
lg_historico
is date?– RFL
Excuse me, the lg_historic and desc_database field are int(11).
– Bia
To order correctly using dates, are field must be date and not int, just changing the data type of the field your problem must be solved.
– Gildonei
You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? Something needs to be improved?
– Maniero