Unfortunately my SQL skills are very basic. I hope someone can help me. I would like to calculate the logarithmic average over several dBµV values. Unfortunately I cannot use the standard average function as the result are not correct.
Today I have the data in Excel and my calculation works fine. Unfortunately, Excel is now reaching its performance limit and therefore I've imported the data into MS Access (I'm using MS Access Ver Office 365).
I have a table with an ID, frequency and the dBµV values. I would like to get the logarithmic average of all dBµV samples over a certain range of frequencies for a particular ID. The frequency starts at 122 and can go up to 1802. Not every ID has a value for all frequencies.
Frequency ranges can be as follows and never change (means the beginning and the end of the frequency range are constant):
- 122 to 170
- 178 to 226
- 234 to 530
- and so on
In Excel I used the following formula for the frequency range F122_170 (B1:H1 contains the dBµV values):
{=10*LOG(SUM(10^(B1:H1/10))/COUNTA(B1:H1))}
Now I am completely lost with the SQL statement to get the desired result.
Below is an example of my table "tblDev".
| ID | freq | dBuV |
|---|---|---|
| 3977739907 | 122 | 32.44 |
| 3977739907 | 130 | 32.24 |
| 3977739907 | 138 | 31.93 |
| 3977739907 | 146 | 30.79 |
| 3977739907 | 154 | 31.31 |
| 3977739907 | 162 | 32.39 |
| 3977739907 | 170 | 32.43 |
| 3977739907 | 178 | 32.81 |
| 3977739907 | 186 | 32.21 |
| 3977739907 | 194 | 31.23 |
| … | … | … |
The output I would like to have is as follows:
| ID | F122_170 | F178_226 | F234_530 | F770_up |
|---|---|---|---|---|
| 3977739907 | 31.97 | 31.23 | 37.03 | 0.00 |
| 3845056609 | 32.24 | 23.40 | 41.09 | 38.18 |
| 3882949203 | 23.10 | 16.98 | 31.03 | 32.26 |
| ... | ... | ... | ... | ... |
Would be great if someone could help me with the SQL statement.
Best regards Patrik