0

我有一个名为 'rating' 的表,它有两个字段 'cab_id' 和 'rating' 存储出租车的 id 和它的评级为 1 或 0。我想检索值作为向上或向下作为计数总和为 1 或 0 . 我用了两个查询作为

      (SELECT count(rating) as up FROM 

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

     (SELECT count(rating) as down FROM 

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

我想以一个结果的格式检索。

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

         ----------


       1             2         


        ----------

请在这里提供帮助!

4

1 回答 1

2
SELECT
    SUM(IF(rating=1,1,0)) up,
    SUM(IF(rating=0,1,0)) down
FROM rating
WHERE cab_id=101
于 2013-08-09T05:59:07.213 回答