Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

DB2 OLAP question

$
0
0
Looking for help in getting the SQL for Unix DB2 version: DB2 v9.5.0.10.

current table data (pipe delimited for ease of reading):
------------------
CUST_ID | LEVEL | LEVEL_START_DT | LEVEL_END_DT
123|Exective|17/05/2013|01/01/2014
123|Exective|02/01/2014|01/01/2015
456|Exective|02/01/2014|01/01/2015
456|Exective|17/06/2013|01/01/2014
456|High Value|17/05/2013| 16/06/2013
789|Exective|02/01/2014|01/01/2015
789|Exective|17/05/2013|01/01/2014
1123|Exective|02/01/2014|01/01/2015
1123|Exective|17/05/2013|01/01/2014
1456|High Value|02/01/2014|01/01/2015
1456|High Value|17/05/2013|01/01/2014
1789|High value|02/01/2014|01/01/2015
1789|High Value|17/05/2013|01/01/2014


I want to get count of members by their customer id per level per year.
for instance cust_id=123 is Excecutive member between Jan 2, 2013 till Jan 1, 2014, which is how our year is determined and in the next year he/she will be Executive from Jan 2, 2014 to Jan 1, 2015
however Cust_id=456 used to be high vlaue earlier this year but now is excutive (get latest date from present year) so we will not count high value since that is no longer his/her level.

Desired output:
==========
CustCount| LEVEL | LEVEL_START_DT | LEVEL_END_DT
4|Executive|Jan 2, 2013|Jan 1, 2014
2|High Value|Jan 2, 2013|Jan 1, 2014
4|Executive|Jan 2, 2014|Jan 1, 2015
2|High Value|Jan 2, 2014|Jan 1, 2015

Viewing all articles
Browse latest Browse all 13329