How can I sum and replace column data and average everything in MS Access query?

I am pulling data from one table called the parsed Copy and use it to iterate over all the information in another table called the parsed. The columns I am sorting / filtering / manipulating are readings_miu_id, ReadDate, ReadTime, RSSI. I am currently moving data from parsed code to parse using the following sql to only get the last time (highest value in ReadTime since it is wartime formatted) for each unique readings_miu_id and ReadDate pair.

SELECT readings_miu_id, Reading, ReadDate, ReadTime, MIUwindow, SN, Noise, RSSI, ColRSSI,MIURSSI,Firmware,CFGDate,FreqCorr,Active,MeterType,OriginCol,ColID,Ownage,SiteID,PremID, prem_group1, prem_group2,ReadID  
    INTO analyzed  
    FROM analyzedCopy AS A  
    WHERE  ReadDate BETWEEN #04/21/09# AND #04/29/09#  AND ReadTime=  (SELECT TOP 1 analyzedCopy.ReadTime FROM analyzedCopy  
    WHERE analyzedCopy.readings_miu_id = A.readings_miu_id  AND analyzedCopy.ReadDate = A.ReadDate  
    ORDER BY analyzedCopy.readings_miu_id, analyzedCopy.ReadDate, analyzedCopy.ReadTime DESC)

   ORDER BY A.readings_miu_id, A.ReadDate, A.ReadTime DESC ; 

      

I need to add to this code the ability to put in the table "parsed" one record at a time readings_miu_id

on change ReadDate

to show the desired date range (in this case it will need to show something like "4/21/09 to 4/29/09") as well as taking the average of the RSSI values ​​for each DISTINCT reading_miu_id

and inserting that average RSSI into the RSSI field in the parsed table.

In trying to recap / overview, I have code to insert into a table all records from another table where ReadTime

is the highest for each unique combination readings_miu_id

and ReadDate. And I need to add to this code the ability to take the average RSSI of the already sorted (step in the previous sentence) records and insert that average into the RSSI in the parsed state and insert the date range ReadDate

into the analysis.

I realize that I am probably asking a lot here and if I need to use two or three different steps or SQL code, that's ok. the program in question will not be used by many people and my boss doesn't care if the code gets messy or if it takes a little time to run. I cringe when forced to do such things ineffectively and erratically, but that's what I am forced to do.

I have to use a function sum()

to sum the RSSI values, which I am not sure exactly how to do, dividing the sum by the amount for each DISTINCT readings_miu_id

and doing whatever else I need to do to that data. Using VB.NET 2008 and sqlServer, I can run each row through some boolean statements to do what I need for the data, but I don't know how to do it in SQL or VBA.


Edit:

If I don't explain something well enough, please let me know and I'll try to correct and add information to the best of my ability.

+1


a source to share


1 answer


Solving a problem one problem at a time. Create tables for each step, AnalyzedStep1, AnalyzedStep2, etc.



0


a source







All Articles