robertsquestion
Technical User
Hi,
I'm using MS Access 2003 on Windows XP and I've got a question about selecting specific records from my database.
The tables are defined as follows:
Table 1 : T_Customer
Customernr (primary key)
Customername
Table 2 : T_Sales
Customernr
Periodnr
Article_group
Sales_euro
(primary key is combination of Customernr/Periodnr/Article_group)
I've create a relationship between the 2 Customernr-fields.
Now what I need is the "Sales_euro" per customernr per article_group per periodnr from the last 4 available(!) periodnrs. The last periodnr per customernr could be different, not all customers buy in all periods. There are only 3 different article_groups (A, B and C). If there are sales in one period, the period should be selected (if it is in the last 4 periods within that customer).
Now I've tried to solve this with "select top 4" (on periodnr) in my query. I had to create a few different (sub)queries to get a result. But the final query is quite slow, even in my test-database that has got only 4.000 records. There will be around 100.000 records in the actual database.
Some example records in table T_Sales:
1247;200701;A;80
1247;200701;B;100
1247;200701;C;60
1247;200702;A;800
1285;200701;A;60
etc.
Does anyone know a nice and clean solution to solve this? (without having to create too many different queries which makes the final query quite slow)
Thanks in advance for your help!
Regards,
Robert
The Netherlands
I'm using MS Access 2003 on Windows XP and I've got a question about selecting specific records from my database.
The tables are defined as follows:
Table 1 : T_Customer
Customernr (primary key)
Customername
Table 2 : T_Sales
Customernr
Periodnr
Article_group
Sales_euro
(primary key is combination of Customernr/Periodnr/Article_group)
I've create a relationship between the 2 Customernr-fields.
Now what I need is the "Sales_euro" per customernr per article_group per periodnr from the last 4 available(!) periodnrs. The last periodnr per customernr could be different, not all customers buy in all periods. There are only 3 different article_groups (A, B and C). If there are sales in one period, the period should be selected (if it is in the last 4 periods within that customer).
Now I've tried to solve this with "select top 4" (on periodnr) in my query. I had to create a few different (sub)queries to get a result. But the final query is quite slow, even in my test-database that has got only 4.000 records. There will be around 100.000 records in the actual database.
Some example records in table T_Sales:
1247;200701;A;80
1247;200701;B;100
1247;200701;C;60
1247;200702;A;800
1285;200701;A;60
etc.
Does anyone know a nice and clean solution to solve this? (without having to create too many different queries which makes the final query quite slow)
Thanks in advance for your help!
Regards,
Robert
The Netherlands