此查询未返回我应该的内容:
Select user_id
from subs
where status = 'Failed'
and next_run_dt = '2016-08-04'
and active = '1'
group by user_id having count(status) = 2
表结构和样本数据:
id__|__status__|__next_run_dt__|__user_id__|__active__|
| | | | |
1 | Failed | 2016-08-04 | 3 | 1 |
___|__________|_______________|___________|__________|
| | | | |
2 | Failed | 2016-08-04 | 4 | 1 |
___|__________|_______________|___________|__________|
| | | | |
3 | Failed | 2016-08-04 | 3 | 1 |
___|__________|_______________|___________|__________|
查询应返回
3
的user_id,因为该用户有两个状态为Failed
的条目。如果我删除and next_run_dt = '2016-08-04'
(日期列),查询将返回user_id。
我错过了什么?
编辑:user_id
也可能还有next_run_dt
的空白