SQL query leaving a custom column data

1

Hello

I would like to know if it is possible to mount a query that returns a table like this:

The data of appB and appC comes from a select count in the Calls table that returns me the number of sessions found per application, however the data from appA comes from a different select because it has exception rules. In this case is there any way to merge the selects so that the result of the table above is left?

Thank you!

    
asked by anonymous 14.12.2018 / 14:29

2 answers

1

You can make a union, for example:

SELECT a.aplicacao, a.quantidade FROM tabelaA a
WHERE a.aplicacao = 'appA'
UNION
SELECT b.aplicacao, b.quantidade FROM tabelaB b
WHERE b.aplicacao = 'appB' OR b.aplicao = 'appC';

Remember, for the union to work the selections must be of the same data type.

    
14.12.2018 / 14:38
0

See if that way can help:

SELECT 
(SELECT count(id) FROM appA WHERE condicoes) AS total_appA,
(SELECT count(id) FROM appB WHERE condicoes) AS total_appB,
(SELECT count(id) FROM appB WHERE condicoes) AS total_appC

So you have the result:

--------------------------------------
|total_appA | total_appB | total_appC|
--------------------------------------
| valor A   | valor B    | valor C   |
--------------------------------------
    
14.12.2018 / 14:45