sql - Creating a view with columns based on where clauses -
with of i've been picking little sql today.
i created view this:
create view rdmavwsandbox.vwnim001usersanddlcount select vwnimeventfct.nim_user_id, count(vwnimeventfct.nim_event_type_id) downloadcount rdmavwsandbox.vwnimeventfct nim_event_type_id = 884 group nim_user_id and works fine.
except, column nim_event_type_id has 5 variations: 880,881,883,884,885.
in query above created view count of 884. results like:
nim_user_id | downloadcount because 884 represents download.
but if wanted create view this:
nim_user_id | downloadcount(based884) | someothereventcount(based880) | someothereventcount1(bases 883) | etc is there way , create in 1 view?
put way, i'd count of each instance of 880-885 each nim_user_id
create view rdmavwsandbox.vwnim001usersanddlcount select vwnimeventfct.nim_user_id ,sum(case when nim_event_type_id = 884 1 else 0 end) downloadcount ,sum(case when nim_event_type_id = 885 1 else 0 end) ,sum(case when nim_event_type_id = 886 1 else 0 end) ,sum(case when nim_event_type_id = 887 1 else 0 end) rdmavwsandbox.vwnimeventfct group nim_user_id how one?
Comments
Post a Comment