Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to select last 6 months (names)

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how to select last 6 months (names)

select 'VIP' as type, strftime('%m', 'now') AS month


If this month is October,
I want to select
VIP 10
VIP 9
VIP 8
VIP 7
VIP 6
VIP 5
how do I do that?
Thanks
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a subtable called month
but it can't wrap around for 10-12 months before when this month is 10 etc
if I do
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like an operation I'd rather do in Java (or other client language) instead of SQL (if possible, of course).

Perhaps combining the month.month field with current year to obtain an absolute date, and comparing it against a date range computed from the current date would help you manage the wrap-around problem.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!