select  distinct d.name, t.qry_code ,b.info_query_times from qry_log  t left join tdcode b on t.qry_code = b.code_info left join 
tdcode_batch c on b.sys_batch = c.sys_batch left join product d on c.product_id = d.id  left join qry_exception_def e on d.id = e.product_id 
where b.info_query_times>=e.qry_times 
and e.period >= (select ((max(to_date(to_char(a.qry_time,'yyyy-mm-dd hh24-mi-ss'),'yyyy-mm-dd hh24-mi-ss'))-min(to_date(to_char(a.qry_time,'yyyy-mm-dd hh24-mi-ss'),'yyyy-mm-dd hh24-mi-ss'))))*24 
from qry_log a group by a.qry_code) 
在这里and e.period >= 出现了单行子查询出现多个行的错误,请问谁能帮我改过来

解决方案 »

  1.   

    and e.period >= all (select ((max(to_date(to_char(a.qry_time,'yyyy-mm-dd hh24-mi-ss'),'yyyy-mm-dd 
      

  2.   

    select distinct d.name, t.qry_code ,b.info_query_times 
    from  qry_log  t left join tdcode b on t.qry_code     = b.code_info 
          left join tdcode_batch c      on b.sys_batch    = c.sys_batch 
          left join product d           on c.product_id   = d.id  
          left join qry_exception_def e on d.id           = e.product_id 
    where b.info_query_times   >= e.qry_times 
    and   exists (select 1 from qry_log a 
                  where a.qry_code = t.qry_code
                  group by a.qry_code 
                  having (max(a.qry_time)-min(a.qry_time))*24 <=e.period);
      

  3.   

    where a.qry_code = t.qry_code
    这句是关键
      

  4.   

    是的,我也知道 where a.qry_code = t.qry_code 
    这句是关键 ,不过就是写不出来谢谢
      

  5.   

    select  distinct d.name, t.qry_code ,b.info_query_times from qry_log  t left join tdcode b on t.qry_code = b.code_info left join 
    tdcode_batch c on b.sys_batch = c.sys_batch left join product d on c.product_id = d.id  left join qry_exception_def e on d.id = e.product_id 
    where b.info_query_times>=e.qry_times 
    and e.period >= (select ((max(to_date(to_char(a.qry_time,'yyyy-mm-dd hh24-mi-ss'),'yyyy-mm-dd hh24-mi-ss'))-min(to_date(to_char(a.qry_time,'yyyy-mm-dd hh24-mi-ss'),'yyyy-mm-dd hh24-mi-ss'))))*24 
    from qry_log a where qry_code=t.qry_code) 
      

  6.   

    ?#3的没试?你的代码中如果在from qry_log a group by a.qry_code中间加入变成from qry_log a where a.qry_code = t.qry_code group by a.qry_code不确定是否可以,有可能报域范围错误,试试吧
      

  7.   

    qry_time需要to_char再to_date吗?
    可以DISTINCT去重SELECT DISTINCT d.name, t.qry_code, b.info_query_times
      FROM qry_log t
      LEFT JOIN tdcode b
        ON t.qry_code = b.code_info
      LEFT JOIN tdcode_batch c
        ON b.sys_batch = c.sys_batch
      LEFT JOIN product d
        ON c.product_id = d.id
      LEFT JOIN qry_exception_def e
        ON d.id = e.product_id
     WHERE b.info_query_times >= e.qry_times AND
           e.period >=
           (SELECT DISTINCT (MAX(a.qry_time) - MIN(a.qry_time)) * 24 FROM qry_log a GROUP BY a.qry_code);
      

  8.   

    因为 qry_time 类型格式不是 yyyy-mm-dd hh24-mi-ss 的