My sample is a ticketing system, holding entries for status updates and the creation of a ticket.
Fiddle: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=a5ff4600adbab185eb14b08586f1bd29
ID | TICKETID | STATUS | TICKET_CREATED | STATUS_CHANGED |
---|---|---|---|---|
1 | 1 | other_error | 01-JAN-20 | 01-JAN-20 08.00.00 |
2 | 2 | tech_error | 01-JAN-20 | 01-JAN-20 09.00.00 |
3 | 3 | unknown | 01-JAN-20 | 01-JAN-20 09.10.00 |
4 | 4 | unknown | 01-JAN-20 | 01-JAN-20 09.20.00 |
5 | 4 | tech_error | 01-JAN-20 | 02-JAN-20 09.30.00 |
6 | 1 | solved | 01-JAN-20 | 02-JAN-20 10.00.00 |
7 | 2 | solved | 01-JAN-20 | 02-JAN-20 07.00.00 |
8 | 5 | tech_error | 02-JAN-20 | 02-JAN-20 08.00.00 |
9 | 6 | unknown | 02-JAN-20 | 02-JAN-20 08.30.00 |
10 | 6 | solved | 02-JAN-20 | 02-JAN-20 09.30.00 |
11 | 5 | solved | 02-JAN-20 | 03-JAN-20 08.00.00 |
12 | 4 | unknown | 01-JAN-20 | 03-JAN-20 09.00.00 |
I want to evaluate the data based on the ticket creation date, and obtain three things for a specific date:
- (done) how many tickets where totally created on the given date
- (done) how many tickets were created in status 'unknown' on the given date
- (not done) how many tickets were totally in status 'unknown' on the given date? Tricky! Because what matters is the status at the max
STATUS_CHANGED
below midnight of the given date.
Desired result for 01.01.2021:
TICKET_CREATED | Total Created | Tickets created in Unknown status | Total tickets in Unknown status |
---|---|---|---|
01-JAN-20 | 4 | 2 | 2 |
Explanation: on 01-JAN-20, ticket 3 and 4 were in status 'unknown' at end of the day
Desired result for 02.01.2021:
TICKET_CREATED | Total Created | Tickets created in Unknown status | Total tickets in Unknown status |
---|---|---|---|
02-JAN-20 | 2 | 1 | 1 |
Explanation: on 02-JAN-20, only ticket 3 was in status 'unknown' at end of the day
Current solution for part 1 + 2:
select ticket_created,
count(*) as "Total Created",
sum(case when status = 'unknown' then 1 else 0 end) as "Unknown tickets created",
'?' as "Total tickets in Unknown status"
from myTable
where id in
(select min(id) as id
from myTable
where ticket_created = to_date('01.01.2020', 'DD.MM.YYYY')
group by ticketid)
group by ticket_created
Could you give me some hint on how to approach point 3?