0

I have a table which looks like this:

from_user    to_user      type
    43          85          1
    32          43          2
    64          79          1
    77          43          4
    54          43          5
    13          96          4
    78          43          6

I have a variable $user, and I need a query which returns the sum of from_user (i.e. how many from_users are there) where it equals $user, but only if type=1. If type=4 or 5, I need the sum of to_user where it equals $user. Is it possible to do this in one query?

Thanks in advance!

2
  • And what about the other types like 2, 3, or those after 6? Commented Apr 7, 2013 at 15:38
  • is type also an input variable? Commented Apr 7, 2013 at 15:50

1 Answer 1

2
SELECT  SUM(Type = 1 AND From_User = 'user_ID_HERE') From_User,
        SUM(Type IN (4,5) AND to_user = 'user_ID_HERE') To_User
FROM    TableName
Sign up to request clarification or add additional context in comments.

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.