SQL query leaving a custom column data

Asked

Viewed 63 times

1

Hello!

I wonder if it is possible to mount a query that returns me a table similar to this:

inserir a descrição da imagem aqui

The appB and appC data comes from a select Count in the Calls table that returns the amount of sessoes found per application, but Appa data comes from a different select because it has exceptions rules. In this case there is some way to join the selects to get the result of the table above?

Thank you!

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 Union to work selections must be of the same data type.

0

See if this 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’ll get the result:

--------------------------------------
|total_appA | total_appB | total_appC|
--------------------------------------
| valor A   | valor B    | valor C   |
--------------------------------------

Browser other questions tagged

You are not signed in. Login or sign up in order to post.