1

4 colums

| day of year | year | user A | user B |

      1          1      john      ron
      2          1       ron      john
      1          2       john     kyle

i need to count how many times a user appears in either UserA colum or UserB colum

group by UserA colum is not succifient i need to count how many times john appears in total from UserA and UserB cols

expected output

john 3
ron 2
kyle 1

2 Answers 2

4

You appears to want union all

select user, count(*) counts from
(
    select [user A] as user from table t
    union all
    select [user B] as user from table t
)a
group by user
Sign up to request clarification or add additional context in comments.

Comments

1

You can write a query like :-

select user, sum(cnt) total
from 
(select userA as user, count(*) cnt from table group by userA
UNION ALL
select userB as user, count(*) cnt from table group by userB
) a11
group by user

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.