![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I want to writue a query that takes results of a previous query and wants to return all those with a value of 0 but where the previous last 5 records of that field have no zero values. How should I approach this? Can it be done in a query? I think I understand what you want, but I'd rather be sure. Could you show |
#3
| |||
| |||
|
|
colmkav wrote: Hi, I want to writue a query that takes results of a previous query and wants to return all those with a value of 0 but where the previous last 5 records of that field have no zero values. How should I approach this? Can it be done in a query? I think I understand what you want, but I'd rather be sure. Could you show us some sample output from the first query (in tabular format, ommitting the irrelevant columns from your sample - just show enough rows to illustrate the problem), and show us what your desired output would be from the sample (again in tabular format)? |
#4
| |||
| |||
|
|
On May 24, 1:10 pm, "Bob Barrows" <reb01... (AT) NOSPAMyahoo (DOT) com> wrote: colmkav wrote: Hi, I want to writue a query that takes results of a previous query and wants to return all those with a value of 0 but where the previous last 5 records of that field have no zero values. How should I approach this? Can it be done in a query? I think I understand what you want, but I'd rather be sure. Could you show us some sample output from the first query (in tabular format, ommitting the irrelevant columns from your sample - just show enough rows to illustrate the problem), and show us what your desired output would be from the sample (again in tabular format)? This is an example of what the input table/query results look like Client-id AvgCreated transactions (number) Created transactions (number) SumOfTrx EUR amount Processing date 321 61.25 37 3323.764519 10-May-12 321 61.25 64 3368.360543 11-May-12 321 61.25 70 2089.86874 12-May-12 321 61.25 8 319.7241606 13-May-12 321 61.25 55 4633.419834 14-May-12 321 61.25 40 5408.707927 15-May-12 321 61.25 25 3101.684803 16-May-12 321 61.25 119 8539.954168 17-May-12 321 61.25 165 4005.622306 18-May-12 321 61.25 9 447.8219273 19-May-12 321 61.25 8 457 20-May-12 321 61.25 75 8387.034963 21-May-12 321 61.25 43 1224.691638 22-May-12 321 61.25 0 4351.174432 23-May-12 The output for this after the query would be 321 61.25 0 4351.174432 23-May-12 Because the value of created trans on 23 May was 0 but the previous 5 days had values |
#5
| |||
| |||
|
|
colmkav wrote: On May 24, 1:10 pm, "Bob Barrows" <reb01... (AT) NOSPAMyahoo (DOT) com> wrote: colmkav wrote: Hi, I want to writue a query that takes results of a previous query and wants to return all those with a value of 0 but where the previous last 5 records of that field have no zero values. How should I approach this? Can it be done in a query? I think I understand what you want, but I'd rather be sure. Could you show us some sample output from the first query (in tabular format, ommitting the irrelevant columns from your sample - just show enough rows to illustrate the problem), and show us what your desired output would be from the sample (again in tabular format)? This is an example of what the input table/query results look like Client-id AvgCreated transactions (number) Created transactions (number) SumOfTrx EUR amount Processing date 321 61.25 37 3323.764519 10-May-12 321 61.25 64 3368.360543 11-May-12 321 61.25 70 2089.86874 12-May-12 321 61.25 8 319.7241606 13-May-12 321 61.25 55 4633.419834 14-May-12 321 61.25 40 5408.707927 15-May-12 321 61.25 25 3101.684803 16-May-12 321 61.25 119 8539.954168 17-May-12 321 61.25 165 4005.622306 18-May-12 321 61.25 9 447.8219273 19-May-12 321 61.25 8 457 20-May-12 321 61.25 75 8387.034963 21-May-12 321 61.25 43 1224.691638 22-May-12 321 61.25 0 4351.174432 23-May-12 The output for this after the query would be 321 61.25 0 4351.174432 23-May-12 Because the value of created trans on 23 May was 0 but the previous 5 days had values Good thing I asked. Hmmm, I assume your query is set up to provide a record for each client-id for each day with no gaps. I will also assume that [Processing date] is a Date/Time field rather than Text. If so, something like this should suit: select Client-id,[AvgCreated transactions], [Created transactions], [SumOfTrx EUR amount], [Processing date] FROM savedquery as oq WHERE [Created transactions]=0 AND NOT EXISTS (SELECT * FROM savedquery WHERE Client-id=oq.Client-id and [Processing date] >= oq.[Processing date] - 5 and [Processing date] < oq.[Processing date] and [Created transactions] = 0) If [Processing date] is not Date/Time, you will need to convert it to that datatype before doing the date arithmetic: CDate([Processing date]) - 5- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
colmkav wrote: On May 24, 1:10 pm, "Bob Barrows" <reb01... (AT) NOSPAMyahoo (DOT) com> wrote: colmkav wrote: Hi, I want to writue a query that takes results of a previous query and wants to return all those with a value of 0 but where the previous last 5 records of that field have no zero values. How should I approach this? Can it be done in a query? I think I understand what you want, but I'd rather be sure. Could you show us some sample output from the first query (in tabular format, ommitting the irrelevant columns from your sample - just show enough rows to illustrate the problem), and show us what your desired output would be from the sample (again in tabular format)? This is an example of what the input table/query results look like Client-id AvgCreated transactions (number) Created transactions (number) SumOfTrx EUR amount Processing date 321 61.25 37 3323.764519 10-May-12 321 61.25 64 3368.360543 11-May-12 321 61.25 70 2089.86874 12-May-12 321 61.25 8 319.7241606 13-May-12 321 61.25 55 4633.419834 14-May-12 321 61.25 40 5408.707927 15-May-12 321 61.25 25 3101.684803 16-May-12 321 61.25 119 8539.954168 17-May-12 321 61.25 165 4005.622306 18-May-12 321 61.25 9 447.8219273 19-May-12 321 61.25 8 457 20-May-12 321 61.25 75 8387.034963 21-May-12 321 61.25 43 1224.691638 22-May-12 321 61.25 0 4351.174432 23-May-12 The output for this after the query would be 321 61.25 0 4351.174432 23-May-12 Because the value of created trans on 23 May was 0 but the previous 5 days had values Good thing I asked. Hmmm, I assume your query is set up to provide a record for each client-id for each day with no gaps. I will also assume that [Processing date] is a Date/Time field rather than Text. If so, something like this should suit: select Client-id,[AvgCreated transactions], [Created transactions], [SumOfTrx EUR amount], [Processing date] FROM savedquery as oq WHERE [Created transactions]=0 AND NOT EXISTS (SELECT * FROM savedquery WHERE Client-id=oq.Client-id and [Processing date] >= oq.[Processing date] - 5 and [Processing date] < oq.[Processing date] and [Created transactions] = 0) If [Processing date] is not Date/Time, you will need to convert it to that datatype before doing the date arithmetic: CDate([Processing date]) - 5- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |