Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
triplexim32

[mysql] mostrar 2colunas com 2counts

Recommended Posts

triplexim32

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  ;)


<

Share this post


Link to post
Share on other sites
M6

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."

 

Share this post


Link to post
Share on other sites
triplexim32

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)  :)


<

Share this post


Link to post
Share on other sites
M6

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."

 

Share this post


Link to post
Share on other sites
triplexim32

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  :thumbsup:


<

Share this post


Link to post
Share on other sites
M6

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."

 

Share this post


Link to post
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
Sign in to follow this  

×

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.