Re: Query to find sum of grouped counts from 2 tables

From: arafatix(at)gmail(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Query to find sum of grouped counts from 2 tables
Date: 2012-07-12 18:14:14
Message-ID: 8ed8f7fd-080c-4f51-a3d9-9cbf36646059@googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday, January 7, 2011 4:15:25 PM UTC+6, "Satish Burnwal (sburnwal)" wrote:
> I have 2 tables containing the data for same items:
>
> STORE1
> -----------------------------
> Id type items
> -----------------------------
> 1 FOOD 10
> 2 FOOD 15
> 3 SOAP 20
>
> STORE2
> -----------------------------
> Id type items
> -----------------------------
> 1 FOOD 15
> 3 SOAP 10
> 4 PAPER 25
> 5 SOAP 12
>
>
> What I am looking for is one single query that would return me TYPE-wise
> total number of items from both the tables. UNION does not help me. I
> want the result as:
>
> Type count
> -----------------------
> FOOD 40 //10+15+15
> SOAP 42 //20+10+12
> PAPER 25
>
> Thanks in advance,
> -Satish
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

Hello,
I think you can use the sum / count keyword on find query. Follow the link
http://arafats.info/how-to-use-sum-on-cakephp/
Thanks
http://arafats.info

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bartosz Dmytrak 2012-07-12 18:14:40 Re: PostgreSQL limitations question
Previous Message Greg Sabino Mullane 2012-07-12 16:59:17 Re: Bug? Prepared queries continue to use search_path from their preparation time