I want to fetch duplicate rows for a particular date & time, group by both bname and txn_date AND txn_date up to Hours and Minutes (Seconds do not need to match)
For Example, I fetch the rows below for txn_date = 2020/07/28, txn_type = OPD, payment_mode = CREDIT and inv_num begins with AGL
Out of these, I want only rows with IDs from 1 - 4
ID | txn_date | bname
-----------------------------------------------
1 | 2020/07/28 10:21:58 PM | MRS R A W B VERNON
2 | 2020/07/28 10:21:56 PM | MRS R A W B VERNON
3 | 2020/07/28 09:51:58 AM | MRS TRIDENTZ
4 | 2020/07/28 09:51:58 AM | MRS TRIDENTZ
5 | 2020/07/28 09:49:51 AM | MRS TRIDENTZ
6 | 2020/07/28 08:33:14 AM | MRS TRIDENTZ
7 | 2020/07/28 08:25:06 AM | MRS S F D SHERILA
8 | 2020/07/28 08:11:35 AM | MRS S F D SHERILA
I use this query below.
select to_char(l.txn_date,'YYYY/MM/DD HH12:MI:SS AM') "DATE",l.bname
from linv l where (bname) IN (select bname from linv
where txn_date like '28-JUL-20%'
group by bname, txn_date
having count(*) > 1) and l.txn_type = 'OPD' and payment_mode = 'CREDIT'
and inv_num like 'AGL%'
and txn_date like '28-JUL-20%'
order by l.txn_date desc, l.bname
But this does not give me the desired output as some of the required rows are not fetching.
I tried to change group by to to_char(txn_date, 'HH24') but that did not work too.
I think the group_by txn_date has the issue but couldn't get it fixed. Can some one please help?
Thanks!