Skip to content
Advertisement

How to count the difference in Informix SQL?

I’m counting number of rated calls and average rating in callcenter:

(12 rated calls for sales and 4 rated calls for service).

I can also count number of total calls (rated and unrated):

(21 total calls for sales and 4 total calls for service).

But I want to count only unrated calls. SQL request:

runs slowly and produce incorrect result, e.g.

(69 unrated calls for sales and 16 unrated calls for service – incorrect).

Hence count of unrated = total – rated, I can’t build an SQL where I can get this result.

Desired result should be:

(21-12=9 unrated calls for sales and 4-4=0 unrated calls for service).

Example of CALLDATA table:

Finally I have prepared a script for dbfiddle.uk to play with this scenario:

12 rows affected
queue | total
:---- | ----:
SALES |     3
queue | rated
:---- | ----:
SALES |     1
queue | unrated
:---- | ------:
SALES |       8
queue | unrated
:---- | ------:
SALES |       8

db<>fiddle here

Advertisement

Answer

Since you do not want to count the child table, calldata, matched records but only callrecord level records, consider using EXISTS clause (or IN) with correlated subquery:

Online Demo

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement