选择过去24小时内没有记录的所有表格(但最后48个记录中的一些记录等)

时间:2015-02-26 14:05:42

标签: sql oracle

我有一张表(在Oracle数据库中)有

  • 表单名称('name')
  • 创建日期('gmts')
  • 其他栏目(我不在乎)

我可以通过

获得过去24小时的计数
select name, count(name) from table where gmts > sysdate -1 group by name;

(我为了简单而省略了排序)同样,我可以通过玩日期字段随时进行此操作。

我想要做的是显示过去24小时内没有条目的所有表单,但是最后48个表单中的1+表示(因为这可能表示流程存在问题,但不会标记过时的表单)

2 个答案:

答案 0 :(得分:0)

假设这是Oracle,那么:

select name, count(name) 
    from table 
where gmts > sysdate -1 
    or name = (select name from table where gmts > sysdate -2 and rownum <= 1) 
group by name
order by gmts desc;

如果是MySQL使用限制而不是:

select name, count(name) 
    from table 
where gmts > sysdate -1 
    or name = (select name from table where gmts > sysdate -2 order by gmts desc LIMIT 1) 
group by name;

答案 1 :(得分:0)

通过一些搜索,我找到了

select distinct name from table 
  where gmts > systdate - 2 AND
  name NOT IN 
     (select distinct scan_type_nm from document where gmts > sysdate -1)
  order by name asc;
相关问题