pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dani CastaƱos <danitao.mailists@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Get different sums from the same table in one query
Date: Mon, 08 Oct 2007 12:49:04 +0200
Message-ID: <470A0B20.40203@gmail.com> (raw)

Hi all!

I want to put this three queries in only one... Take a look that the 
only thing that changes is the message_type_id. Any suggestions??

         SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, 
sum(total_num_messages)
         FROM statistics_daily
         WHERE message_type_id IN (4,5)
         AND statistics_date = CURRENT_DATE
         AND telecom_operator_id <> 0
         AND telephone_number IN ( $numbers )
         GROUP BY date_in

         SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, 
sum(total_num_messages)
         FROM statistics_daily
         WHERE message_type_id IN (6)
         AND statistics_date = CURRENT_DATE
         AND telecom_operator_id <> 0
         AND telephone_number IN ( $numbers )
         GROUP BY date_in

         SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, 
sum(total_num_messages)
         FROM statistics_daily
         WHERE message_type_id IN (21)
         AND statistics_date = CURRENT_DATE
         AND telecom_operator_id <> 0
         AND telephone_number IN ( $numbers )
         GROUP BY date_in



Thank you in advance!



view thread (5+ messages)  latest in thread

Message-ID: <470A0B20.40203@gmail.com>
Permalink:  ../470A0B20.40203@gmail.com/
Also on:    postgresql.org/message-id/470A0B20.40203@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: danitao.mailists@gmail.com
  Subject: Re: Get different sums from the same table in one query
  In-Reply-To: <470A0B20.40203@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox