SELECT USERNAME, TRUNC(DATE_CREATED)
FROM THE_TABLE
GROUP BY
USERNAME, TRUNC(DATE_CREATED)
HAVING COUNT(*) > 1;
例:
SELECT USERNAME, TRUNC(DATE_CREATED)
FROM
(
SELECT 'a' username, sysdate date_created from dual union all
SELECT 'a' username, sysdate date_created from dual union all
SELECT 'b' username, sysdate date_created from dual union all
SELECT 'b' username, sysdate date_created from dual
)
GROUP BY
USERNAME, TRUNC(DATE_CREATED)
HAVING COUNT(*) > 1;
/*
a 2013-06-18 00:00:00
b 2013-06-18 00:00:00
*/
出力で完全な日付を取得するには、少し複雑です。
SELECT DISTINCT
username
, date_created
FROM the_table ot
WHERE EXISTS
(
SELECT 1
FROM the_table it
WHERE TRUNC(ot.date_created) = TRUNC(it.date_created)
AND ot.username = it.username
GROUP BY
USERNAME, TRUNC(DATE_CREATED)
HAVING COUNT(*) > 1
)
;
/*
a 2013-06-18 12:48:40
b 2013-06-18 12:48:40
*/
テーブルに 2 回アクセスする必要があります + DISTINCT キーワードが必要です。はい、パフォーマンスが低下する可能性があります。