表cc里有 4个字段 分别是:
   substr(tqdt,0,10)
   substr(tqdt,12,14)
   dt
   t1bh
我想查询出 substr(tqdt,0,10),substr(tqdt,12,14)这2个字段同时不重复的结果集。
这个应该怎么写呢?
用group by 有dt,和t1bh 报错 说他们2个不是组里的
用distinct这似乎也不行!
请大家帮帮忙

解决方案 »

  1.   


    select  tqdt_a, tqdt_b,  dt,  t1bh
    from 
    (
      select substr(tqdt,0,10) as tqdt_a, substr(tqdt,12,14) as tqdt_b,  dt,  t1bh,
      row_number() over(partition by substr(tqdt,0,10),substr(tqdt,12,14) order by dt) rn
      from table name 
    ) a
    where a.rn=1
      

  2.   

    select substr(tqdt,0,10),substr(tqdt,12,14) from v_tq_fhyc_z t group by tqdt  order by tqdtselect distinct(substr(tqdt,0,10)),substr(tqdt,12,14),dt,t1bh from v_tq_fhyc_z order by substr(tqdt,0,10)
    select substr(tqdt,0,10) from v_tq_fhyc_z t group by tqdt   union (select substr(tqdt,12,14),dt from v_tq_fhyc_z) order by tqdt想了3种方法都悲剧了!没一个对的!
      

  3.   

    问下楼上的你用什么东西编写的SQl啊 为什么还带颜色的啊PL/SQL我这东西不带啊!你的是什么?
      

  4.   

      substr(tqdt,0,10) substr(tqdt,12,14)   dt               t1bh
    1 2011-11-14 00 2011-10-24 15:51:44 bszdzd01802
    2 2011-11-14 03 2011-10-24 15:51:44 bszdzd01802
    3 2011-11-14 06 2011-10-24 15:51:44 bszdzd01802
    4 2011-11-14 09 2011-10-24 15:51:44 bszdzd01802
    5 2011-11-14 12 2011-10-24 15:51:44 bszdzd01802
    不对啊  substr(tqdt,0,10)还是重复滴!晕了
      

  5.   


    select tqdt_a, tqdt_b, dt, t1bh 
    from ( 
    select substr(tqdt,0,10) as tqdt_a, substr(tqdt,12,14) as tqdt_b, dt, t1bh, row_number() over(partition by substr(tqdt,0,10),substr(tqdt,12,14) order by dt) rn fromv_tq_fhyc_z 
    ) a
    where a.rn=1 
    你把 " 这里写脚本 "  关键字就会有颜色了。
      

  6.   

    substr(tqdt,0,10) 不重复的语句select tqdt_a, tqdt_b, dt, t1bh 
    from ( 
    select substr(tqdt,0,10) as tqdt_a, substr(tqdt,12,14) as tqdt_b, dt, t1bh, row_number() over(partition by substr(tqdt,12,14) order by dt) rn fromv_tq_fhyc_z 
    ) a
    where a.rn=1 
      

  7.   

    哦!还以为你用什么特殊编辑器呢!原来是csdn自己带的啊!
    啊我知道原因了!唉!看来只能分成2个语句了!
     一个是查
    substr(tqdt,0,10)
    一个是查
    substr(tqdt,12,14)
    分别来分组了!一个是不可能实现的
      

  8.   

    其实我的数据这样的
    我想查出substr(tqdt,0,10),和substr(tqdt,12,14)
    字段分别 只有1,substr(tqdt,0,10),条 14 号 15号的数据  
    和 substr(tqdt,12,14) 00 03 06 一条的!
    刚仔细想了下似乎一条语句实现不聊必须分开查来实现