Oracle 19c
We have a requirement where we want to provide some report data from Event table, Event and Item table has schema like this
    CREATE TABLE EVENT
       (    
        "ID" NUMBER(19,0) NOT NULL ENABLE, 
        "CREATED" TIMESTAMP (6) NOT NULL, 
        "CUSTOMER_ID" VARCHAR2(255 CHAR) NOT NULL, 
        "CONF_ID" VARCHAR2(255 CHAR), 
        "STATE" VARCHAR2(255 CHAR) NOT NULL,
        "ITEM_ID" VARCHAR2(255 CHAR) NOT NULL
        ...
       )
    CREATE TABLE ITEM
    (   
        "ID" NUMBER(19,0) NOT NULL ENABLE,
        "NAME" VARCHAR2(255 CHAR) NOT NULL
        ....
        primary key (ID)
    )
  alter table EVENT
   add constraint EVENT_FK_ITEM_BID
      foreign key (ITEM_ID)
      references ITEM;
where events are created with different states as per real time occurrance. Events are bound to Item Table with Item_id.
What we want to achieve select count of Event States (only consider the latest state per item_id), grouped by CUSTOMER_ID and CONF_ID.
Event table could have more than 2 million rows.
result should look like
CUSTOMER_ID CONF_ID ACIVATED DEACTIVATED    SUSPENDED
----------  ------- -------- -------------  ---------
1             2      50000    20000          5000
1             1      70000    30000          2000
2             1      80000    10000          10000
2             2      50000    20000          5000 
Could you please guide us building an efficient query?
 
    