Hi there,I have problem with this query. I am trying to find all those customers who 1)Shopped in 2003 only and did not shop in 2004,2005,20062)Shopped in 2004 only and did not shop in 2005,20063)Shopped in 2005 only and did not shop in 20064)Shopped in 2006 onlyFor the above you want to see the total customers in each group and then the total pointsSo the first thing I did was to find all those customers who shopped in 2003-2006 because the above totals should add back to these values See the code belowMY CHECKselect count(distinct cardnumber), sum(ransactionpoints)from transaction c where (transactiondate >= '20030101' and transactiondate < '20070101')
And lets say the total spend for the period is 1,000 and the total points 500.When I run the query for each of the criteria mention above, and I add the total spend for each month and I add the total points I get a break down down like this. So it doesn't come back out to the CHECKJust like my query the Total Customer column is correct but the total points is not correct. Total Customers Total Points2003 200 102004 500 302005 100 402006 150 52007 50 1 _________ _______ 1000 86
Please see below for the quriesselect distinct c.cardnumber,sum(dailytransactionvalue)from SubsidiaryByCustomerByClassTransactionDetail c where c.cardnumber in ( select distinct cardnumber from ubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20030101' and transactiondate < '20040101') and cardnumber not in ( select distinct cardnumber from SubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20040101' and transactiondate < '20080101') ) )
select distinct c.cardnumber,sum(dailytransactionvalue)from SubsidiaryByCustomerByClassTransactionDetail c where c.cardnumber in ( select distinct cardnumber from ubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20040101' and transactiondate < '20050101')and cardnumber not in ( select distinct cardnumber from SubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20050101' and transactiondate < '20080101') ) )
select distinct c.cardnumber,sum(dailytransactionvalue)from SubsidiaryByCustomerByClassTransactionDetail c where c.cardnumber in ( select distinct cardnumber from ubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20050101' and transactiondate < '20060101')and cardnumber not in ( select distinct cardnumber from SubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20060101' and transactiondate < '20080101') ) )
select distinct c.cardnumber,sum(dailytransactionvalue)from SubsidiaryByCustomerByClassTransactionDetail c where c.cardnumber in ( select distinct cardnumber from ubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20060101' and transactiondate < '20070101')and cardnumber not in ( select distinct cardnumber from SubsidiaryByCustomerByClassTransactionDetail where (transactiondate >= '20070101' and transactiondate < '20080101') ) )
select distinct c.cardnumber,sum(dailytransactionvalue)from SubsidiaryByCustomerByClassTransactionDetail c where (transactiondate >= '20070101' and transactiondate < '20080101')
Any Ideas? I was wonder if i was to do a group by year(transactiondate) would that give me customers who shopped only in 2003 ,only in 2004 ,only in 2005 etc and their spend?? e.g 5 customers shopped in 2004 and did not shop in 2005,2006,or 2007 and they spent $20 combinesI am not sure if this will show the info that I really want.Thanks for looking at my questionso something like thisselect distinct c.cardnumber, sum(dailytransactionvalue), year(transactiondate)from SubsidiaryByCustomerByClassTransactionDetail c where (transactiondate >= '20030101' and transactiondate < '20080101')group by year(transactiondate)