根据类别和日期对列进行分组,并返回Oracle中每个类别的最新类别和相应结果

时间:2016-09-26 03:00:23

标签: sql oracle

所需输入:

<ul id="parent">
  <li class='menu-item'>
    Menu Title 1
    <div id="popup">
      <p>Popup data</p>
    </div>
  </li>
  <li>Menu 2</li>
  <li>Menu 3</li>
  <li>Menu 4</li>
</ul>

所需的输出是

 emp id | appointment_id | appointment_type | assessment_date | Result_id | Res_Date 
 100115 | 77382          | HAEC1            | 06.10.2009      | 1234      | 07.10.2009
 100115 | 77890          | HAEC1            | 07.10.2009      | 1256      | 12.10.2009
 100115 | 77890          | HAEC1            | 07.10.2009      | 1156      | 12.10.2009
 100115 | 77111          | HAEC1            | 07.10.2015      | 1296      | 12.10.2015
 100115 | 77222          | HAEC1            | 09.10.2016      | 1246      | 12.10.2016
 100115 | 77222          | HAEC1            | 09.10.2016      | 1346      | 12.10.2016
 100115 | 77222          | HAEC1            | 09.10.2016      | 1446      | 12.10.2016
 100115 | 77333          | HAB1             |09.10.2016       |1246       | 12.10.2016
 100115 | 77444          | HAC1             | 09.10.2016      | 1246      | 12.10.2016
 100115 | -77555         | HAC3             | 09.10.2016      | 1246      | 12.10.2016

1 个答案:

答案 0 :(得分:0)

猜测您想要的过滤器是基于assessment_date的值,并且所有appointment_id的负值都不是拼写错误:

select emp id
       , case when appointment_id > 0 then
                   appointment_id * -1 
               else appointment_id 
        end as appointment_id 
      , appointment_type
      , assessment_date
      , Result_id
      , Res_Date
from your_table
where assessment_date > sysdate
/