D
D
Dmitry Mityaev2019-09-01 16:38:18
Oracle
Dmitry Mityaev, 2019-09-01 16:38:18

Is it possible to display several COUNTs with a condition in one selection?

Is it possible to do something like this in PL SQL:
Select
a,
b,
c,
COUNT (D ****** WHERE D = 'tino'),
COUNT (D ****** WHERE D = 'tipo' '),
COUNT (D ****** WHERE D = 'tiko')
FROM
TABLE A
JOIN TABLE B ON a.id = b.id
GROUP BY ******
In general, can COUNT somehow condition to work?
Or what are the alternative ways?
I need to display several quantities summed by conditions in one report (to sum only with codes 'tino', 'tipo' and 'tiko')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-09-01
@erge

and take and just write, instead of asking?
COUNT does not count NULL

SELECT
    key,
    count(DECODE(value, 'tino',1, NULL)) AS tino,
    count(DECODE(value, 'tipo',1, NULL)) AS tipo,
    count(DECODE(value, 'tiko',1, NULL)) AS tiko
  FROM table1
  GROUP BY key

see on sqlfiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question