Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic