0

結合で重複したレコードを取得しています。NSANOTES.NOTEDATE の最大 (最新) 日付のみが必要です。どうやってそれをしますか?

SELECT NSAACTIVITY.NSAID ,
NSAACTIVITY.NSASERVICEIMPACTED "Type",  
NSAACTIVITY.NSAAPPROVED,
NSAACTIVITY.NSADESCRIPTION,
NSANOTES.NSANOTE 
FROM NSAUSER.NSAACTIVITY INNER JOIN NSAUSER.NSANOTES ON NSAACTIVITY.NSAID=NSANOTES.NSAID
WHERE TO_CHAR(NSAACTIVITY.NSASTART, 'yyyy-mm-dd hh24:mi') BETWEEN '2013-06-28 10:59:59' AND '2013-07-01 06:00:01'
4

3 に答える 3

1

group by を使ってみましたか?何かのようなもの:

SELECT NSAACTIVITY.NSAID ,
NSAACTIVITY.NSASERVICEIMPACTED "Type",  
NSAACTIVITY.NSAAPPROVED,
NSAACTIVITY.NSADESCRIPTION,
NSANOTES.NSANOTE,
MAX(NSANOTES.NOTEDATE)
FROM NSAUSER.NSAACTIVITY INNER JOIN NSAUSER.NSANOTES ON NSAACTIVITY.NSAID=NSANOTES.NSAID
WHERE TO_CHAR(NSAACTIVITY.NSASTART, 'yyyy-mm-dd hh24:mi') BETWEEN '2013-06-28 10:59:59' AND '2013-07-01 06:00:01'
GROUP BY NSAACTIVITY.NSAID ,
NSAACTIVITY.NSASERVICEIMPACTED,  
NSAACTIVITY.NSAAPPROVED,
NSAACTIVITY.NSADESCRIPTION,
NSANOTES.NSANOTE 
于 2013-06-28T15:17:25.100 に答える
0

このようなものがうまくいくと思います(サブクエリを使用)

SELECT NSAACTIVITY.NSAID ,
NSAACTIVITY.NSASERVICEIMPACTED "Type",  
NSAACTIVITY.NSAAPPROVED,
NSAACTIVITY.NSADESCRIPTION,
ns.NSANOTE 
FROM NSAUSER.NSAACTIVITY INNER JOIN NSAUSER.NSANOTES ns ON NSAACTIVITY.NSAID=ns.NSAID
WHERE TO_CHAR(NSAACTIVITY.NSASTART, 'yyyy-mm-dd hh24:mi') BETWEEN '2013-06-28  10:59:59' AND '2013-07-01 06:00:01'
and ns.NOTESDATE= (SELECT MAX(ns2.NOTESDATE) FROM NSAUSER.NSANOTES ns2 where ns2.NSAID = ns.NSAID)
于 2013-06-28T15:17:43.623 に答える