Can have averages as my "values" for the "insert" function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can have averages as my "values" for the "insert" function?

I'm trying to obtain an average from the data of a weather station that gives data every 5 secs. Moreover, i need to insert this data into another table that will have just averages. Also i need to do the same for 10 min averages.

22nd Oct 2018, 7:00 AM
Mauricio Manuel Canto Romero
Mauricio Manuel Canto Romero - avatar
3 Answers
0
What is the problem? Get the values, calculate the average and store this in the table..
22nd Oct 2018, 11:17 AM
KrOW
KrOW - avatar
0
KrOW i already got the averages separately, but couldnt insert those values in a table in just one query. Is there a way to save those values as variables? To get the averages i used this query: SELECT avg(a) as avg_a, avg (b) as avg_b from prueba WHERE ID >= ((SELECT COUNT(ID) FROM prueba)-7); I'm trying to do it as one Query because I'm using c# to connect the weather station to the database and need to insert the data in those tables automatically Greetings from Mexico.
22nd Oct 2018, 1:58 PM
Mauricio Manuel Canto Romero
Mauricio Manuel Canto Romero - avatar
0
I just solved this like this for know: Insert Into promedios (prom_a,prom_b, prom_c) select avg(a), avg(b), avg(c) from prueba WHERE ID >= ((select count(ID) from prueba)-1); is there a way to group by each minute and 10 minute lapse instead of using the count function? 'cause i'm leaving the program running for several days and need to get those averages. The other option i'm thinking of is having (on C#) some for loops where i use the query above, something like this: //code loop { for (int i=0; i<10; i++) { for (int j=0; j<12; j++) { //code to get the weather station lectures to MySQL (table1) } //query to insert 1 min averages (table2) } //query to insert 10 min averages (table3) }
22nd Oct 2018, 2:40 PM
Mauricio Manuel Canto Romero
Mauricio Manuel Canto Romero - avatar