[英]trying to get average of 2 entries in mysql database with same time and on specific date
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试图在 mysql 数据库中获得相同时间和特定日期的 2 个条目的平均值,但如果同时有多个条目[在此处输入图像描述
db image DB structure db image数据库结构
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就像上面所附的照片一样,我们有 3 个 8:30 的条目,但我只想要在同一日期输入的前两个条目的平均值,所以我该怎么做,谁能帮忙
i want the average of welding strength我想要平均焊接强度
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.您需要做的就是在welding_entry_ids 上自连接同一张表,第二张表的welding_id 应该比第一张表的welding_id 大1。 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;)
因此您可以轻松地编辑查询并进行必要的更改;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.