Here is a dummy table to describe what I am trying to do:
ID_1 | ID_2 | ID_3 | Day | Energy_Costs |
----------+----------+------------+-------+---------------+
State_1 | County_1 | Building_1 | 1 | 48.8 |
State_1 | County_1 | Building_1 | 2 | 31.3 |
State_1 | County_1 | Building_2 | 1 | 20.5 |
State_1 | County_2 | Building_1 | 1 | 1.9 |
State_2 | County_1 | Building_1 | 1 | 6.6 |
State_2 | County_2 | Building_2 | 1 | 38.2 |
State_2 | County_2 | Building_2 | 2 | 12.0 |
In the table above, a unique record (a Building in this case), requires 3 columns (ID_1, ID_2, ID_3). I would like to return a table with the first row of a given day for a building.
Here's how the query looks in my head:
SELECT FIRST(ID_1), FIRST(ID_2), FIRST(ID_3), FIRST(Energy_Costs), FIRST(DAY)
FROM buildings_db
GROUP BY ID_1, ID_2, ID_3
ORDER BY DAY
This would return:
ID_1 | ID_2 | ID_3 | Day | Energy_Costs |
----------+----------+------------+-------+---------------+
State_1 | County_1 | Building_1 | 1 | 48.8 |
State_1 | County_1 | Building_2 | 1 | 20.5 |
State_1 | County_2 | Building_1 | 1 | 1.9 |
State_2 | County_1 | Building_1 | 1 | 6.6 |
State_2 | County_2 | Building_1 | 1 | 38.2 |
I've seen other questions asking something similar but they typically don't have multiple columns defining a group. I'm very new to SQL so translating them to my example is proving unsuccessful; if any of you can provide an explanation for why your solution works that would be very helpful.