Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Help for construct Query
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 30th April 19:59
viaris
External User
 
Posts: 1
Default Help for construct Query



Hi all,

I have the following two tables, the table correo have the messages send
using the mail, the other table web have the message send using web.

I have the following query:

select SUBSTR(hora,1,2) as ho,count(*) as tot from web as a where
fecha='11/20/03' group by SUBSTR(hora,1,2);

select SUBSTR(hora,1,2) as ho,count(*) as tot from correo as a where
fecha='11/20/03' group by SUBSTR(hora,1,2);

my result is:

hour | messages
------+---------
00 | 35
01 | 9
02 | 4
04 | 1
05 | 9
06 | 42
07 | 132
08 | 446
09 | 505

But I need have only one query for both tables, I was trying but I can't,
how can I do it?

Thanks in Advanced.

---------------------------(end of broadcast)---------------------------
TIP 8: explain ****yze is your friend
  Reply With Quote


  sponsored links


2 30th April 19:59
chris
External User
 
Posts: 1
Default Help for construct Query



[snip]

Have you looked into UNION?

Also, are the tables indentical in all but name? If so, perhaps consolidating
the two tables and add a field to be used to distinguish between the two types
of messages?

Chris


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org
  Reply With Quote
3 30th April 19:59
viaris
External User
 
Posts: 1
Default Help for construct Query


Him Thanks for you answer, at this moment I can't consilidate the two
tables, we are redisign the system, but at this moment I need this datas for
a report.

I used UNION, but I have the problem that the count(*) when not found rows
no print the the hour, If my the hour 3 AM no have rows I need that this
hour have 0.

Example
Results
===========
hour | messages
------+---------
00 | 35
01 | 9
02 | 4
04 | 1
05 | 9
06 | 42
07 | 132
08 | 446
09 | 505

I need
=======
hour | messages
------+---------
00 | 35
01 | 9
02 | 4
03 | 0
04 | 1
05 | 9
06 | 42
07 | 132
08 | 446
09 | 505


----- Original Message -----
From: "Chris Boget" <chris@wild.net>
To: "Viaris hotmail" <viaris@hotmail.com>; <pgsql-novice@postgresql.org>
Sent: Friday, November 21, 2003 9:30 AM
Subject: Re: [NOVICE] Help for construct Query


can't,

consolidating

types


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666