vendredi 8 mai 2015

a query in sql server

I have a table with this field in sql server : user_id , seller_id , cat_id , brand_id , action_type

action_type values is 0 , 1 , 2 , 3

I want a query that can show me per "user_id and seller id "

the number of 0 fileds from action type

the number of 1 fileds from action type

the number of 2 fileds from action type

the number of 3 fileds from action type

fo example :

user1 seller1 cat1 brand1 0

user1 seller1 cat1 brand1 0

user1 seller1 cat2 brand1 1

user1 seller1 cat2 brand1 0

user1 seller1 cat1 brand1 0

user1 seller1 cat3 brand1 2

user1 seller1 cat3 brand1 2

user1 seller1 cat4 brand1 2

i want a table in output that can show me the number of action type: the column of output table is :

user_id seller_id , seller action_type_0 , action_type_1 ,action_type_2 action_type_3

output:

user1 seller1 4 1 3

description"

4:number of 0 in action_type per seller_id and user_id

1:number of 1 in action_type per seller_id and user_id

2:number of 2 in action_type per seller_id and user_id

Aucun commentaire:

Enregistrer un commentaire