Let's say I have a table with two columns, id
and hash
:
id | hash
------------------
1 | bb
2 | aa
3 | aa
4 | bb
I need to order them by id
(descending), yet group all the rows that have the same value. An algorithm that did this would be for example:
- Gather into disjunct subsets the table so that the columns for which
hash
is the same are together.
- Sort the subsets by the their maximum
id
, descending.
- The subsets rows may optionally be sorted by
id
, descending.
The result would be
id | hash
------------------
4 | bb
1 | bb
3 | aa
2 | aa
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…