Reputation: 33
I'm a bit new to PL/SQL and I'm not sure what the best approach is to compare the data from the same table.
So there is a table that stores User Settings, but not all users have the same settings. It's best I show it in a snippet of an example:
User Setting Value
---- ------- -----
Carol Timezone GMT
Carol PageSize 300
Greg Timezone EST
Greg PageSize 300
Greg Duration 10
Bill PageSize 250
Bill Duration 20
Fred Timezone 30
... ... ...
Let's say there are thousands of users. I want to somehow compare the values between Carol, Greg, and Bill but do not want to include of the others (Fred, etc).
Is it possible to have the table look something like this?
Setting Carol Greg Bill
------- ----- ----- ----
Timezone GMT EST (null)
PageSize 300 300 250
Duration (null) 10 20
Upvotes: 0
Views: 48
Reputation: 204766
select setting,
max(case when user = 'Carol' then value else null end) as Carol,
max(case when user = 'Greg' then value else null end) as Greg,
max(case when user = 'Bill' then value else null end) as Bill
from your_table
WHERE user IN ('Carol','Greg','Bill')
group by setting
Upvotes: 1