mardi 13 septembre 2016

Reward points and create new fields in original table

I have a table here : enter image description here

I want to reward a gold and a silver(i.e a value of 1 wherever applicable,else 0 )to top 2 persons by looking at pointsRewarded field.

I already have the first table created.In the first table, the two new fields should be created i.e the gold and silver fields.

i want the output to be something like this: enter image description here

Please help me with the query or give me some suggestions on how to proceed.

I have some query suggested to be:

select t.*,
   (case when rnk = 1 then 1 else 0 end) as gold,
   (case when rnk = 2 then 1 else 0 end) as silver
from (select t.*,
     dense_rank() over (partition by week order by pointsrewarded) as rnk
from t
 ) t;

But I want the new fields i.e rank,gold and silver to be added in the first table.Don't want it as a view.I want the new fields to be hardcoded in the original table.

Please help me with the query or give me some suggestions on how to proceed.

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire