-2

Currently I am retrieving data month wise from below query

select  month(EntryDate) as m, sum(QTY) as QTY,Sum(IWeight) as Weight
from ConIssuance

where delid is null
group by  month(EntryDate)
Order by month(EntryDate) asc

Output Is coming

enter image description here

But i want below like output ( Means I want Last Year Month come above to till year month)

enter image description here

  • 1
    Order by year(EntryDate) asc, month(EntryDate) asc ? or order by case when month(getdate)<month(entrydate) then 1 else 0 end asc, month(entrydate)? – Akina Jun 30 at 7:18
  • Please, tag one DBMS only. – McNets Jun 30 at 7:21
  • ok @McNet Noted ,,and Thanks Akina – Akhter Hussain Jun 30 at 7:31
  • @Akina 's first solution is probably the best one. A slight variant of the second one would be to order by mod( month(entrydate)+12-month(getdate), 12) – Lennart Jun 30 at 8:37
  • @Lennart I am not sure that OP collects data over last year period only - maybe this is statistic over a lot of years... – Akina Jun 30 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.