2016-11-29 66 views

回答

0

假設你真的表示 「32」,而不是 「31」,然後row_number()是典型的方法:

select t.* 
from (select t.*, 
      row_number() over (partition by workorder_id order by seq_id desc) as seqnum 
     from t 
     where sts = 'Closed' 
    ) t 
where seqnum = 1; 
+0

謝謝戈登 – shivareddy

2

嘗試這種情況:

SELECT sts 
     ,workorder_id 
     ,MAX(SEQ_ID) AS Last_Seq_ID 
FROM mytablename 
WHERE sts = 'Closed' -- Only include Closed records 
GROUP BY sts, workorder_id 
ORDER BY workorder_id -- This line is optional; it will sort your result 
+0

謝謝你serge – shivareddy

0

試試這個:

select workorder_id,max(seq_id) as seqid 
from testtable 
where sts='Closed' 
group by workorder_id 
+0

謝謝你ranjana – shivareddy

1

這將工作的32

SELECT workorder_id 
     ,max(seq_id) 
from your_table 
where sts="Closed" 
group by workorder_id 
相關問題