我想通过ID向我展示最近提交的记录,但我只想在最近的这两个日期之间找到它。但是,它不允许我分组。
select id, type, location_id, max(submitted)
from events
where type='status'
and max(submitted) between '2014-08-05' and '2014-08-22'
group by id
答案 0 :(得分:4)
使用having
max()
子句
select id, type, location_id, max(submitted)
from events
where type='status'
group by id, type, location_id
having max(submitted) between '2014-08-05' and '2014-08-22'