想选出每条hphm的相关信息,要求hphm不能相同,下面的语句并不能实现,因为每个clbh的值都不相同,所以会出现相同的hphm
select distinct(hphm),clbh from xxfl where jllx='0' and scbj=0  and (jgsj between to_date( '2008-08-30 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2008-08-30 15:00:00','yyyy-mm-dd hh24:mi:ss')); 
请教各位不吝赐教

解决方案 »

  1.   

    hphm和clbh是一对多的关系吗。没看懂你要问什么哦
      

  2.   


    select hphm,max(clbh) from xxfl 
    where jllx='0' and scbj=0  
    and (jgsj between to_date( '2008-08-30 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2008-08-30 15:00:00','yyyy-mm-dd hh24:mi:ss')) 
    group by hphm; 
      

  3.   

    select hphm,clbh from (select hphm,clbh,row_number() over(partition by hphm order by clbh) rn from xxfl ) where rn=1 and jllx='0' and scbj=0  and (jgsj between to_date( '2008-08-30 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2008-08-30 15:00:00','yyyy-mm-dd hh24:mi:ss'));
      

  4.   

    SELECT HPHM,MIN(CLBH) FROM ... GROUP BY HPHM;
    SELECT HPHM,MAX(CLBH) FROM ... GROUP BY HPHM;SELECT HPHM,CLBH FROM (..., ROW_NUMBER() OVER(PARTITION BY HPHM ORDER BY HPHM) "RN" ...) ... RN = 1;
    SELECT HPHM,CLBH FROM (..., RANK() OVER(PARTITION BY HPHM ORDER BY HPHM) "RO" ...) ... RO = 1;
    SELECT HPHM,CLBH FROM (..., DENSE_RANK() OVER(PARTITION BY HPHM ORDER BY HPHM) "DR" ...) ... DR = 1;