Skip to content
Advertisement

Calculating percentages based on a few columns in a subgroup

I have a table (let’s call it Table A) like this:

I would like to build a table (let’s call it Table B) from A above like this:

Again from Table B, I’d like to derive Table C where the Updated Device column for each of the ID will carry the name from the Device column only if the Percentage is >=95%. If the percentage split between Devices for each ID is anything else, we’ll simply set UpdatedDevice to Others. For example, using the data in Table B, we’ll get a Table C like below:

I am wondering if there’s a way to do this with advanced SQL windowing/analytical functions in one shot instead of generating intermediate tables.

Advertisement

Answer

test setup: http://rextester.com/XKBNO39353

returns:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement