3

I have a Table containing facebook Ids of my users and I have to make a report on who is using facebook or not.

For the facebook user, the datarow contains a number else it contains null

My result have to be like that :

NbUsers Facebook 1000 no 500 yes 

I don't know how to construct my query!

Any help will be helpfull!

Thanks a lot!!

2
  • give your table structure. Commented Jul 8, 2013 at 10:48
  • Do you have any column saying its ur ID or facebook ID ,,, something like IsFacebook ? .. need to know schema Commented Jul 8, 2013 at 10:48

1 Answer 1

2

you can do it easily by case statement :

SELECT SUM(CASE WHEN FACEBOOKID IS NULL THEN 1 ELSE 0 END) AS NbUsers , 'NO' AS FACEBOOK FROM USERTABLE UNION ALL SELECT SUM(CASE WHEN FACEBOOKID IS NULL THEN 0 ELSE 1 END) AS NbUsers , 'YES' AS FACEBOOK FROM USERTABLE 
Sign up to request clarification or add additional context in comments.

1 Comment

I suggest you format your answer and put every selected column on its own row.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.