Skip to content
Advertisement

Altering a query to show the overall sum of the numbers combined

I was wondering if there was a way to alter the below query to show the overall results

SELECT STATUS ,count( * )
FROM vicidial_list
WHERE list_id
BETWEEN 2732900  AND 2732905
GROUP BY 1
ORDER BY 1

This is what it currently shows

STATUS  count( * )
A   32
AA  1386
ADC 57
B   21
DNC 50
DROP    70
LR  21
N   36
NA  319
NC  38
NL  7
PDROP   6
R   45
RD  1136
RO  506
SALE    102
TP  3
WN  6

Is there a way to alter the query to show the sum of just the A, AA, B, Drop, N, NA, NC, and PDROP so when I run the query it will just give me all these status codes added up?

What I would like to show

STATUS  count( * )
A   32
AA  1386
B   21
DROP    70
N   36
NA  319
NC  38
PDROP   6

Total = 1908 The overall sum of these status codes are most important

Advertisement

Answer

something like this :

SELECT status
      ,count(*) counts
FROM vicidial_list
WHERE list_id BETWEEN 2732900 AND 2732905
and status in ('A', 'AA', 'B', 'Drop', 'N', 'NA', 'NC', 'PDROP') 
GROUP BY status with rollup
ORDER BY 1

db<>fiddle here

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