select count(DISTINCT t0.A0100) from A001A001 t0,H001A001 t1
 where 1=1  and t1.A0107='1'  and t1.A0100=t0.A0100
 and t1.INUMBER in(select t1.INUMBER 
 from H001A001 t1, A001A001 t0
 where t1.A0100=t0.A0100 
 and t1.NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss') and rownum < 2)

解决方案 »

  1.   

    to :wupangzi(无本之木) 这个和sql server运行结果相差太大了,,
      

  2.   

    哦,我是根据你写的
    select count(DISTINCT t0.A0100) from A001A001 t0,H001A001 t1
     where 1=1  and t1.A0107='1'  and t1.A0100=t0.A0100
     and t1.INUMBER in(select t1.INUMBER 
     from H001A001 t1, A001A001 t0
     where t1.A0100=t0.A0100 
     and t1.NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss') )进行转换!
    如果要根据
    select t0.A0100 from A001A001 t0,H001A001 t1
     where 1=1  and t1.A0107='1'  
     and t1.INUMBER=(select top 1 INUMBER from H001A001 g0
     where g0.A0100=t0.A0100 
     and g0.NEWDATETIME<='2004-04-23 18:45:00' 
     order by g0.NEWDATETIME desc)
    那么要复杂一点!
    select t0.A0100 from A001A001 t0,H001A001 t1
     where 1=1  and t1.A0107='1'  
     and t1.INUMBER=(select INUMBER from (select INUMBER from H001A001 g0
     where g0.A0100=t0.A0100 
     and g0.NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyymmdd') 
     order by g0.NEWDATETIME desc) where rownum < 2);
      

  3.   

    select t0.A0100 from A001A001 t0,H001A001 t1
     where 1=1  and t1.A0107='1'  
     and t1.INUMBER=(select INUMBER from H001A001 g0
     where g0.A0100=t0.A0100 
     and g0.NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss') and rownum=1)--不知道你第一where后为什么要有一个1=1? 
      

  4.   

    to :wupangzi(无本之木) 提示无效的列名,where g0.A0100=t0.A0100 
    oracle 好像不能解析外面的 t0
      

  5.   

    select t0.A0100 from A001A001 t0,H001A001 t1
     where 1=1  and t1.A0107='1'  
     and t1.INUMBER=(select INUMBER from (select INUMBER from H001A001 g0
     where g0.A0100=t0.A0100 
     and g0.NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss') 
     order by g0.NEWDATETIME desc) where rownum=1);
      

  6.   

    我自己在从句里面加上 A001A001 t0 后提示 未选定行
      

  7.   

    to  ORARichard(没钱的日子好难过啊)你的也是提示 无效的列名,where g0.A0100=t0.A0100 我自己在从句里面加上 A001A001 t0 后提示 未选定行
      

  8.   

    你把表结构和要求写出来吧,我觉得你原来的SQL语句不好
      

  9.   

    SELECT T0.A0100
              FROM A001A001 T0, H001A001 T1
             WHERE 1 = 1
               AND T1.A0107 = '1'
               AND T1.INUMBER =
                    SELECT *
                      FROM (SELECT GO.*,
                             RANK() OVER(ORDER BY G0.NEWDATETIME DESC) RK
                        FROM H001A001 G0
                       WHERE G0.A0100 = T0.A0100
                         AND G0.NEWDATETIME <= '2004-04-23 18:45:00')
                     WHERE RK = 1
      

  10.   

    SELECT T0.A0100
        FROM A001A001 T0, H001A001 T1
       WHERE 1 = 1
         AND T1.A0107 = '1'
         AND T1.INUMBER =
              SELECT INUMBER
                FROM (SELECT GO.INUMBER INUMBER,
                       RANK() OVER(ORDER BY G0.NEWDATETIME DESC) RK
                  FROM H001A001 G0
                 WHERE G0.A0100 = T0.A0100
                   AND G0.NEWDATETIME <= '2004-04-23 18:45:00')
               WHERE RK = 1
      

  11.   

    主要是统计总数,符合下面的要求。A001A001 是一个主表,H001A001 是一个日志从表要求是 主表中有限制条件,或者日志表中也有限制条件,如:t1.A0107='1'  并且要保证,日志表中返回唯一的,截止日期前的最新的一条记录,,就是在 sql server 中用 top 1  的原因(从表是外健与主表的主健关联的),INUMBER是从表的唯一数(类似主健)
      

  12.   

    try:select t0.A0100 from A001A001 t0,(select * from H001A001 where rowid=select max(rowid) from HOO1A001 where A0107='1' and NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss'))t1
     where 1=1 and t0.number=t1.number
      

  13.   

    select t0.A0100 from A001A001 t0,(select * from H001A001 where rowid=(select max(rowid) from HOO1A001 where A0107='1' and NEWDATETIME<=to_date('2004-04-23 18:45:00','yyyy-mm-dd hh24:mi:ss'))) t1
     where 1=1 and t0.number=t1.number
    前面的少了对'()'