Jump to content

[mysql] mostrar 2colunas com 2counts


triplexim32
 Share

Recommended Posts

Quero basicamente contar da mesma tabela o total de 2 registos diferentes e mostra-los em 2  colunas lado a lado, ou seja:

Tenho as PM (Mensagens privadas) quero mostrar em 2 colunas o total das que estão na pasta Inbox e Outbox:

Assim consigo mostrar uma coluna apenas com o total da pasta 'Inbox':

SELECT count( *  ) FROM PMS WHERE folder = 'Inbox'

Eu quero juntar a pasta 'Inbox' e 'Outbox' lado a lado

Em q o resultado seria:

_____________

|Inbox  | Outbox|

|---------|----------|

| 120    |  57      |

'---------'-----------'

Alguma ideia?

Obrigado desde ja  😉

<

Link to comment
Share on other sites

Quick and dirty:

select (SELECT count(*) FROM PMS WHERE folder = 'Inbox') as In, select count(*) as Out from PMS where folder = 'Outbox') FROM DUAL;
10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Quick and dirty:

select (SELECT count(*) FROM PMS WHERE folder = 'Inbox') as In, select count(*) as Out from PMS where folder = 'Outbox') FROM DUAL;

ta a dar um erro:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN, SELECT count(*) AS Out FROM PMS WHERE folder = 'Outbox') FROM DUAL' at line 1

(deste ja um muito obrigado pela ajuda)  🙂

<

Link to comment
Share on other sites

Sim, o IN é uma palavra reservada, chama-lhe ENTRADA.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Ainda da erros

Testei assim

SELECT  (SELECT count(*) FROM PMS WHERE folder = 'Inbox'  AS ENTRADA , SELECT count(*) AS Saida FROM PMS WHERE folder = 'Outbox')  FROM Dual ;

E assim:

SELECT  (SELECT count(*) FROM PMS WHERE folder = 'Inbox'  AS ENTRADA , SELECT count(*) AS Saida FROM PMS WHERE folder = 'Outbox')  FROM PMS ;

E assim:

SELECT  (SELECT count(*) FROM PMS WHERE folder = 'Inbox' AS ENTRADA , SELECT count(*) FROM PMS WHERE folder = 'Outbox' AS Saida) FROM Dual

nada  👍

<

Link to comment
Share on other sites

Tens erros de sintaxe nessas queries?

Sem dizeres qual é o erro que te dá, não é possível ajudar.

Esta query deve funcionar:

SELECT  (SELECT count(*) FROM PMS WHERE folder = 'Inbox')  AS Entrada, (SELECT count(*) AS Out FROM PMS WHERE folder = 'Outbox')  as Saida FROM DUAL;

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.