robertsquestion
Technical User
Hi,
I'm using a database on a SQL-server that contains the sales from a few dealers to different endusers per period. So each dealer has got his own endusers. Now the goal is to analyse the number of new endusers compared to the previous period. Outcome should be grouped (on row-level) per enduser age-group (0-40, 40 - 60, >60). There are only 2 periods per year. The number of new endusers should be displayed as a total and also split per gender.
An additional issue is that only dealers that have sales in both the current and previous period should be considered.
So let's say we're using table 'T_Sales' with the following fields + example records:
Dealernr / Endusernr / Birthyear / Gender / Period / Sales
100 / 9000 / 1950 / M / 200901 / 200
100 / 9200 / 1960 / M / 200901 / 180
100 / 9000 / 1950 / M / 200902 / 250
100 / 9300 / 1940 / M / 200902 / 420 (*)
100 / 9400 / 1960 / M / 200902 / 350 (*)
100 / 9500 / 1985 / F / 200902 / 180 (*)
200 / 8500 / 1920 / M / 200902 / 260
200 / 8600 / 1945 / M / 200902 / 300
I've marked the records that contain new endusers with a (*). The endusers from dealer 200 are not considered because there are no sales for this dealer in previous period (200901).
So the result would be:
Age-group descr. / Total / Male / Female
Age-group 0 - 40 / 1 / 0 / 1
Age-group 40 - 60 / 1 / 1 / 0
Age-group >60 / 1 / 1 / 0
Now I'm quite an amateur when it comes to SQL.. I can do this with 6 different queries and finally in the MS Access frontend with a crosstab-query. But I was hoping that maybe someone out there knows a more clever SQL-solution. As the table is quite big, the performance of my current solution is quite bad..
To make things worse, I need the same thing for the 'disappeared' endusers (so endusers with sales in periode 200901 and no sales in periode 200902 for dealers that have sales in both periods). But hopefully I can figure this one out myself if someone knows the solution for the new endusers.
I hope someone can help me out!
Thanks,
Robert
The Netherlands
I'm using a database on a SQL-server that contains the sales from a few dealers to different endusers per period. So each dealer has got his own endusers. Now the goal is to analyse the number of new endusers compared to the previous period. Outcome should be grouped (on row-level) per enduser age-group (0-40, 40 - 60, >60). There are only 2 periods per year. The number of new endusers should be displayed as a total and also split per gender.
An additional issue is that only dealers that have sales in both the current and previous period should be considered.
So let's say we're using table 'T_Sales' with the following fields + example records:
Dealernr / Endusernr / Birthyear / Gender / Period / Sales
100 / 9000 / 1950 / M / 200901 / 200
100 / 9200 / 1960 / M / 200901 / 180
100 / 9000 / 1950 / M / 200902 / 250
100 / 9300 / 1940 / M / 200902 / 420 (*)
100 / 9400 / 1960 / M / 200902 / 350 (*)
100 / 9500 / 1985 / F / 200902 / 180 (*)
200 / 8500 / 1920 / M / 200902 / 260
200 / 8600 / 1945 / M / 200902 / 300
I've marked the records that contain new endusers with a (*). The endusers from dealer 200 are not considered because there are no sales for this dealer in previous period (200901).
So the result would be:
Age-group descr. / Total / Male / Female
Age-group 0 - 40 / 1 / 0 / 1
Age-group 40 - 60 / 1 / 1 / 0
Age-group >60 / 1 / 1 / 0
Now I'm quite an amateur when it comes to SQL.. I can do this with 6 different queries and finally in the MS Access frontend with a crosstab-query. But I was hoping that maybe someone out there knows a more clever SQL-solution. As the table is quite big, the performance of my current solution is quite bad..
To make things worse, I need the same thing for the 'disappeared' endusers (so endusers with sales in periode 200901 and no sales in periode 200902 for dealers that have sales in both periods). But hopefully I can figure this one out myself if someone knows the solution for the new endusers.
I hope someone can help me out!
Thanks,
Robert
The Netherlands