[英]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 我有一个名为'rating'的表,它有两个字段'cab_id'和'rating',它存储cab的id及其等级为1或0.我希望将值作为向上或向下检索为计数总和为1或0我使用了两个查询
(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 ! 请在这里帮忙!
SELECT
SUM(IF(rating=1,1,0)) up,
SUM(IF(rating=0,1,0)) down
FROM rating
WHERE cab_id=101
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.