Search Posts

how to delete and update the rows when converetd mins data to hours in database

this is continuation of the post
need database hourly data before two months

hostname              | cpuload | freedisk  | freemem |timestamp 
 localhost.localdomain | 0.15    | 136052    | 383660  | 2017-08-01 00:10:08 
 localhost.localdomain | 0.03    | 136492    | 383660  | 2017-08-01 00:20:08 
 localhost.localdomain | 0.01    | 133456    | 383660  | 2017-08-01 00:30:08 
 localhost.localdomain | 0.10    | 64544     | 383660  | 2017-08-01 00:40:08 
 localhost.localdomain | 0.01    | 68148     | 383660  | 2017-08-01 01:00:08

output obtained is

hostname                cpuload     freedisk      freemem
-------------------------------------------------------------
localhost.localdomain   0.072500    117636.0000   383660.0000
localhost.localdomain   0.010000    68148.0000    383660.0000

i used query

SELECT t1.hostname
    ,avg(cpuload) AS cpuload
    ,avg(freedisk) AS freedisk
    ,avg(freemem) AS freemem
FROM table1 t1
WHERE t1.TIMESTAMP < current_timestamp - interval '42' day
GROUP BY date_format(t1.TIMESTAMP, '%Y%m%d%H');

Here i want to insert the results obtained to same table and delete the 2 months ago data where we did the operation.

Please help me

Thanks in advance

sagar reddy

Source: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *