This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes how to select last 6 months (names) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "how to select last 6 months (names)" Watch "how to select last 6 months (names)" New topic
Author

how to select last 6 months (names)

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 634

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

Joined: Aug 02, 2012
Posts: 634
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

Joined: Aug 22, 2010
Posts: 3718
    
  61

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to select last 6 months (names)
 
It's not a secret anymore!