I have a Table with Sort
and Status
fields.
I need to create a Query with 2 fields: LastStatus
and Times
.
First field shows (sorting per Sort) the status of last record. The second shows how many records, in end of table, has the same value.
Example
When the query result is this:
| Sort | Status |
| ------------ | ------------ |
| 1 | alpha |
| 2 | bravo |
| 3 | charlie |
| 4 | alpha |
| 5 | alpha |
| 6 | charlie |
| 7 | alpha |
| 8 | alpha |
| 9 | alpha |
Expected result:
LastStatus | Times |
---|---|
alpha | 3 |
Thanks!
3条答案
按热度按时间xwbd5t1u1#
On second read, it is more of a Gaps-and-Islands problem
Example or dbFiddle
Results
hfwmuf9z2#
you can use window function(lead and First_value for find Times
zlhcx6iw3#
The solution below gets the number of the last row in the last sequence of the
Status
value using only descending sort.db<>fiddle