Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get count of IDs based on related values in other column and creation time

RameshSagarJul 29 2020 — edited Jul 31 2020

Hi All,

I am really in need of help in querying the single table. The table I need to query will have thousands of data and due to limitations and the masking, I cannot post the DDLs and DMLs and data dump, Apologies for this. I will try to be as detailed as possible

DB : Oracle 12C and SQL Developer

Table: Caller_Details

SERIAL_NUMBERCALLER_IDTAGIS_DELETEDTIME
1444Active02020-06-04 14:27:52.390
2666Active02020-06-04 14:28:24.440
3111Passive02020-06-04 14:28:27.217
4222Active12020-06-04 14:28:27.600
5333Passive02020-06-04 14:28:41.743
6111Active02020-06-04 14:28:57.020
7222Active02020-06-04 14:28:57.563
8222Passive02020-06-04 14:29:00.187
9555Passive02020-06-04 14:29:08.300

Data Types:

SERIAL_NUMBER = Integer and Primary Key

CALLER_ID = Integer

TAG = Varchar

IS_DELETED = Integer

TIME = Timestamp

Requirement:

I need to get the count of callers i.e count(distinct CALLER_ID) who are registered to both 'Active' as well as 'Passive' and out of these two, the registration to 'Active' is first (based on Time) which is not deleted.

Note:

IS_DELETED column specifies if the registration exists or marked as deleted.

0 = Not Deleted

1 = Deleted

I tried using rank function to check if I could order the records, but not really sure what next I should be doing. Appreciate any help here.

select  count(caller_id) from (

select tag, caller_id, time,

rank() over (order by time asc) rnk_on_time

from  caller_details

where is_deleted=0

and tag in ('Active', 'Passive')

) dummy

This post has been answered by L. Fernigrini on Jul 29 2020
Jump to Answer
Comments
Post Details
Added on Jul 29 2020
12 comments
3,083 views