Mysql 将大于和小于的SQL查询合并为一个查询
我有以下两个问题:Mysql 将大于和小于的SQL查询合并为一个查询,mysql,sql,Mysql,Sql,我有以下两个问题: select count * form a where temp>str group by x,y select count * form a where temp<=str group by x,y select count*form a where temp>str按x,y分组 选择count*form a,其中temp尝试以下操作: SELECT SUM(CASE WHEN `temp` > `str` THEN 1 ELSE 0 END) A
select count * form a where temp>str group by x,y
select count * form a where temp<=str group by x,y
select count*form a where temp>str按x,y分组
选择count*form a,其中temp尝试以下操作:
SELECT
SUM(CASE WHEN `temp` > `str` THEN 1 ELSE 0 END) AS `greater`,
SUM(CASE WHEN `temp` < `str` THEN 1 ELSE 0 END) AS `less`
FROM
`a`
GROUP BY
`x`,
`y`
选择
求和(当'temp'>'str'时为1,否则为0结束)为'greater',
总和(当'temp`<'str`时为1,否则为0结束)为'less`
从…起
`a`
分组
`x`,
`y`
试试这个:
SELECT
SUM(CASE WHEN `temp` > `str` THEN 1 ELSE 0 END) AS `greater`,
SUM(CASE WHEN `temp` < `str` THEN 1 ELSE 0 END) AS `less`
FROM
`a`
GROUP BY
`x`,
`y`
选择
求和(当'temp'>'str'时为1,否则为0结束)为'greater',
总和(当'temp`<'str`时为1,否则为0结束)为'less`
从…起
`a`
分组
`x`,
`y`
选择总和(如果(temp>'str',1,0))作为更大值,
sum(如果(temp'str',1,0))返回1,如果大于1,则返回0。将这些值相加将得到更大的RWO总数
如果(温度<代码>选择总和(如果(温度>'str',1,0))更大,
sum(IF(temp'str',1,0))如果大于,则返回1,否则返回0。将这些值相加将得到大于的RWO总数
如果(temp),请你也解释一下查询。结果集看起来怎么样?请你也解释一下查询。结果集看起来怎么样?请你也解释一下查询。结果集看起来怎么样?请你也解释一下查询。结果集看起来怎么样?