I was hoping someone can help me out here.
I am trying to write a query in mysql and i am having a really hard time getting the syntax right. Let me explain what I am trying to do.
I have a table that houses measurement data for construction and each entry has a location_id, room_id, measurement_value, floor_num, measurement_date. I am trying to write a query to get the latest measurement data from each floor (there are only two floors). so I was thinking something like this but I can’t get it to work.
select bottom_floor.value as bottom_value, top_floor.value as top_value
from
(select measurement_value, measurement_date, floor_num, room_id from rom_measurements where location_id = '1' and floor_num='1' order by measurement_date DESC limit 1) as bottom_floor
Join
(select measurement_value, measurement_date, floor_num, room_id from rom_measurements where location_id = '1' and floor_num='2' order by measurement_date DESC limit 1) as top_floor
So I thought that this would give me back the two values. I have seen that if one of the two subqueries returns an empty set it doesn’t work and I am also pretty sure I have done other things wrong here.
Can someone recommend a better way to accomplish this?
Thanks!
Total square for all rooms on the floor:
Square for each room on the floor: