trying to get average of 2 entries in mysql database with same time and on specific date

Viewed 26

Trying to get average of 2 entries in mysql database with same time and on specific date, but if there are multiple entries on same time[enter image description here

db image DB structure

Like in the above attached photo we have 3 entries of 8:30 but i just want the average of first two entries entered on same date, so how can i do it, can any one please help

i want the average of welding strength

enter image description here

1 Answers

All you need to do is self join same table on welding_entry_ids, welding_id of second table should be 1 more than welding_id of first table. So that will combine alternate records in a single record. And after that all you need to do is take the avg of both the strengths present in the same record.

Try this code below, just add your table name and the date you want average for.

SELECT ((strength1+strength2)/2) 
FROM 
(SELECT a.welding_strength strength1,b.welding_strength strength2 
FROM table_name a, same_table_name b 
WHERE a.welding_entry_id+1=b.welding_entry_id and entry_date="add_your_date" LIMIT 1) c;

I think now you have an idea of how to do and what to do. So you can easily edit the query and make necessary changes ;)

Related