user1659213
user1659213

Reputation: 101

Duplication/Updation of data in mysql

I want to get the sum of the data for every 5 minutes. I have 15 motes. for ,suppose in the first 5 minutes only some motes are queried and in the next 5 minutes other some motes are queried. Now,In the second 5 minutes I need the data of the motes which are not queried in that 5minutes also ie.,in the first 5minutes moteid's 1,2,3,4,9,12,14 are queried and in the second minutes moteid's 1,5,6,7,9,13,14 are queried. In the second 5 minutes,I need the data to be updated for the one's which are not queried also.Is it possible to get the data from the previous 5 minutes

moteid2 | 28 | 2012-09-25 17:45:43 | | 
moteid4 | 65 | 2012-09-25 17:45:49 | | 
moteid3 | 66 | 2012-09-25 17:45:51 | | 
moteid6 | 25 | 2012-09-25 17:45:56 | | 
moteid5 | 29 | 2012-09-25 17:45:58 | | 
moteid7 | 30 | 2012-09-25 17:46:05 | | 
moteid4 | 95 | 2012-09-25 17:50:29 | | 
moteid6 | 56 | 2012-09-25 17:50:35 | | 
moteid5 | 58 | 2012-09-25 17:50:36 | | 
moteid4 | 126 | 2012-09-25 17:55:08 |

In the first 5 minutes moteid2, moteid3 are queried, but after that in the next 5minutes they are not queried. Even If they are not being queried i want the same previous queried value to be kept now.

Upvotes: 0

Views: 44

Answers (1)

alexkorep
alexkorep

Reputation: 531

I'm assuming the table name is motes. In this case the following query displays all unique motesid for the records which present in the whole table but were not queried in last 5 minutes:

select distinct m.motesid
from motes m
where not exists (
    select *
    from motes m1
    where 
        m1.moteid = m.motesid and
        m1.date > SUBTIME(CURTIME(), '0:05:00')
)

Upvotes: 1

Related Questions