3

I have a table with multiple readings_miu_id's each with multiple RSSI readings (RSSI is also the name of the field). So, i currently have a datasheet, with many columns, but the two pertinent ones to this conversation look something like this:

readings_miu_id  RSSI
===============  ====
11011032         -90
11011032         -81
11011032         -62
11011032         -84
11011032         -86
11010084         -84
11010084         -86
11010084         -87

and so on.

My original plan was to change the value of RSSI for each record having the same readings_miu_id with the average RSSI for that readings_miu_id (which should look the same as above except that the individual RSSI's will be replaced by the average RSSI for that miu), and then pull only one record for each distinct readings_miu_id (which I'm pretty sure I can do with the select top 1 type statement.) However I'm having problems figuring the first part out. The sql statements I've tried that seem like they should be close are:

UPDATE analyzedCopy2 as A 
SET analyzedCopy2.RSSI = Avg(RSSI) 
where readings_miu_id = A.readings_miu_id

and

UPDATE analyzedCopy2 as A 
SET RSSI = Avg(select RSSI from analyzedCopy2 
    where readings_miu_id = A.readings_miu_id) 
WHERE readings_miu_id = A.readings_miu_id;

Help please!

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
Bryan
  • 1,851
  • 11
  • 33
  • 56
  • 2
    Retagged to remove "avg" and "update" tags. Neither is a really a category IMO, and avg has also been used for the anti-virus software in another post. Feel free to put them back if anyone disagrees. – John M Gant May 21 '09 at 16:36
  • 1
    So does anyone know why I'm being down-voted here? – Bryan Jun 12 '09 at 18:45
  • 1
    @Bryan, I really don't understand what is wrong with people on StackOverflow today - I've seen a lot of bizarre downvotes. This is a good question, well written, nicely formatted. Can't understand why it's been downvoted. I upvoted it for you. – Rob Jun 12 '09 at 20:23
  • 1
    my guess as for the downvote reason would be the "yet another ms-access sql question" part of the title... – dotjoe Jun 12 '09 at 20:54
  • @unforgiven3 Oh it's not just today. Someone has been harassing me by down-voting all of my posts for a few days now because I posted a suggestion he didn't like and a few others have since then been doing the same. – Bryan Jun 12 '09 at 20:55
  • @dotjoe I had used that because it was about the 3rd ms-access sql question I had asked in a day or two. But if you think that is the reason then I have no problems removing it and thanks for the suggestion. – Bryan Jun 12 '09 at 20:58

3 Answers3

0

Not sure why you want to update the records.

If you just want an avg reading you can do this:

SELECT readings_miu_id, AVG(RSSI)
FROM analyzedCopy2 
GROUP BY readings_miu_id
DJ.
  • 16,045
  • 3
  • 42
  • 46
  • I need all of the information from all of the queries im doing to be continuously stored in tables because all the information in the table is what i need, not just the avg(RSSI) and once im done the data is viewed in a form with a list box that uses a table as it's source. And since this is a project i inherited from my predecessor, im being forced to do things in much the same way – Bryan May 21 '09 at 18:00
0

Please see this question, where a similar scenario is discussed.

The query you are looking for is something like this (I don't have an SQL shell here so there may be slight syntax problems):

UPDATE analyzedCopy2 AS target
INNER JOIN 
(
    select avg(RSSI) as AvgRSSI, readings_miu_id
    from analyzedCopy2 T
    group by readings_miu_id
) as source
ON target.readings_miu_id = source.readings_miu_id
SET target.RSSI = source.AvgRSSI
Community
  • 1
  • 1
Roee Adler
  • 33,434
  • 32
  • 105
  • 133
0

See:

ACC: Update Query Based on Totals Query Fails

"This behavior is a design limitation... There are three methods of working around this behavior..."

onedaywhen
  • 55,269
  • 12
  • 100
  • 138