Jojo George
Jojo George

Reputation: 159

how to combine result of two queries in one resultset

I have a table named 'rating' it has two fields 'cab_id' and 'rating' which stores id for cabs and its rating as either 1 or 0. I want to retrieve values as up or down as sum of counts as 1 or 0. I used two queries as

      (SELECT count(rating) as up FROM 

     `rating` WHERE cab_id=101 and rating=1 )

and

     (SELECT count(rating) as down FROM 

     `rating` WHERE cab_id=101 and rating=0 )

I want to retrieve in the format of one result .

         ----------
      up          down

         ----------


       1             2         


        ----------

Please lend a help here !

Upvotes: 0

Views: 62

Answers (1)

nosid
nosid

Reputation: 50024

SELECT
    SUM(IF(rating=1,1,0)) up,
    SUM(IF(rating=0,1,0)) down
FROM rating
WHERE cab_id=101

Upvotes: 2

Related Questions