SQL查询在两个值之间HAVING SUM

时间:2017-02-16 13:22:32

标签: mysql sql

目前我有查询要求Sums降低2

 `HAVING SUM(`Place` < 2)`

是否可以将它设置在两个值1.5和2之间

 `HAVING SUM(`Place` between 2 and 1.5)`

我的整个查询如下:

SELECT `tile`, `Date`, SUM(`Place` < 2) as sumtotal
FROM TFResults
GROUP BY `tile`, `Date`
HAVING SUM(`Place` between 2 and 1.5)  > 1 ;

3 个答案:

答案 0 :(得分:0)

你可以在之间使用

SELECT `tile`, `Date`, SUM(`Place` < 2) as sumtotal
FROM TFResults
GROUP BY `tile`, `Date`
HAVING  SUM(`Place` ) between 1.5 and 2 ;

答案 1 :(得分:0)

更改表ID的table_key:

select `tile`, `Date`, SUM(`Place` < 2) as sumtotal
where table_key in (
(   SELECT table_key
        FROM TFResults
        GROUP BY `tile`, `Date`
        HAVING SUM(`Place` < 2)  > 1 )
AND
(   SELECT table_key 
        FROM TFResults
        GROUP BY `tile`, `Date`
        HAVING SUM(`Place` > 1.5)  > 1 )
)

答案 2 :(得分:0)

尝试以下方法:

SELECT `tile`, `Date`, SUM(`Place` < 2) as sumtotal
FROM TFResults
GROUP BY `tile`, `Date`
HAVING SUM((`Place` <= 2) AND (`Place` =>  1.5))  > 0 ;