'SQL select multiple columns according to current month
I want to select previous months column from a table. So for example: if the current month is April I want to select columns Jan, Feb and March. I tried using CASE but the problem with a one condition you can only select one column, and once the condition is matched then it will ignore subsequent when statements.
EDIT
Sample Data
var_d | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
O/P for April
var_d | Jan | Feb | Mar |
---|---|---|---|
A | 1 | 1 | 1 |
Likewise in May we need April's data too
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|