I'm not sure if I described it correctly. I have a list of servers, users and permissions.
The permissions is in there multiple times because it could be in there in multiple groups. This is a gerneral format to the data.
| system | userid | role |
| ------------ | ------------ | ------------ |
| server1 | bill | user |
| server1 | bill | administrator |
| server1 | joe | user |
| server1 | ted | administrator |
| server2 | bill | user |
| server2 | joe | remote_user |
| server2 | joe | user |
| server3 | ted | administrator |
| server3 | ted | remote_user |
| server3 | bill | user |
What I am looking to return is the highest permission set. Administrator is above remote_user. Remote_user is above user.
system | userid | role |
---|---|---|
server1 | bill | administrator |
server1 | joe | user |
server1 | ted | administrator |
server2 | bill | user |
server2 | joe | remote_user |
server3 | ted | administrator |
server3 | bill | user |
Thanks for any suggestions offered.
I tried finding some examples with 'With' but most examples involve averages.
3条答案
按热度按时间x6yk4ghg1#
You can use
ROW_NUMBER()
to find the rows you want, according to any ordering criteria, specified by theORDER BY
clause.For example:
sr4lhrrt2#
Just adding an alternative technique, something I'd call double shuffle:
First you convert the text to a number level which can be aggregated on, then you convert it back to the text representation.
but5z9lq3#
You could simply tag the elements with a prefix that's rankable and then strip it out at the end. This would work on a system without analytic functions. It also doesn't involve translating values back and forth so the ranking expression only needs to be written a single time: