SELECT ID, Serial, ProcessHours, t_stamp
FROM machine_data md
INNER JOIN
(SELECT Serial, MAX(t_stamp) AS MaxTStamp
FROM machine_data
GROUP BY home) groupedmd
ON md.home = groupedmd.home
AND md.datetime = groupedmd.MaxTStamp
WHERE Type = 'BLAST'
I’m not saying this is it, exactly, without some data to query against, but it may give you some ideas.
The grouping is possibly not valid. In the SQL standard, when grouping, every column/expression in the select list must be either in the Group By clause, or have an aggregate function. Most DBs enforce this. MySQL lets you do it, and it “just works” if the one grouping key is unique for the unspecified columns, but otherwise yields pseudo-random results. You aren’t grouping by ProcessHours in your inner query.
With your advice and some googling it got me on the right track.
select sum(ProcessHours)
from (SELECT
MAX(ProcessHours) as ProcessHours
FROM `machine_data`
where type = 'BLAST'
group by serial) a
I record the hours run of all the machines of a certain category when they post their info via MQTT. The trouble is there is many records as they post each hour so I only wanted to pick the newest one or in the case I chose the highest value as effectively its the same.