Context
I have this table:
Time | Metric A | Metric B | Value |
---|---|---|---|
A | A | A | 1 |
A | A | B | 2 |
A | A | C | 1 |
B | A | A | 1 |
B | A | B | 2 |
B | A | C | 1 |
I want to get the last and summarize the table by Metric A, but sometimes Time goes bonkers and GROUP BY Time is not an option.
What I want is to get the last value of Metric B for each Metric A… Any tips on how to make sure I get the last inserted value for Metric B for Metric A?
Desired output
Time | Metric A | Metric B | Value |
---|---|---|---|
A | A | A | 1 |
A | A | B | 2 |
A | A | C | 1 |
2
Answers
You could use rank() or dense_rank() to achieve what you’re looking for.
View on DB Fiddle
Using a subquery:
See fiddle