Re: Help : Sum 2 tables based on key from other table

From: Hengky Liwandouw <hengkyliwandouw(at)gmail(dot)com>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Help : Sum 2 tables based on key from other table
Date: 2013-11-18 09:42:30
Message-ID: 91CE293C-6576-463D-8DC4-80E6EB075945@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks all for your concern and help.

I have tried David suggestion and it works. As what you all said, there are so many important feature in PostgreSQL. I really have to spend time to study it.

Last time i use Windev to develop front end application, and HyperfileSQL as the database server. This makes me headache :D

Postgre really fast, has excellent feature, clear documentation, has great community and really so many plus point.

Thanks you all.

On Nov 18, 2013, at 4:47 PM, Raymond O'Donnell wrote:

> On 18/11/2013 02:16, Hengky Liwandouw wrote:
>> Dear Friends,
>>
>> Please help for the select command, as i had tried many times and
>> always can not display the result as what i want.
>>
>> I am looking for the solution on google but still can not found the
>> right answer to solve the problem.
>>
>> I have 3 tables :
>>
>> Table A ProductID ProductName SupplierID
>>
>> Table B ProductID InitialStock
>>
>> Table C ProductID Date In Out
>>
>> 1. I want to select all productID from Table A where
>> supplierID='XXX'.
>>
>> 2. Based on list from Step.1 : sum the initialstock from Table B
>>
>> 3. Based on list from Step 1 : Sum (in-out) from Table C where date
>> <'BEGINNING DATE'
>>
>> 4. Based on list from Step 1 : Sum (in) and sum(out) from Table C
>> where date between 'BEGINNING DATE' and 'ENDING DATE'
>>
>> So the result will look like this :
>>
>> ProductID ProductName SumofIntialStock sum(in-Out)<beginningdate
>> SumofIN SumofOut xxxx xxxxxxxxxxxxx 99
>> 99 99 99 xxxx
>> xxxxxxxxxxxxx 99 99
>> 99 99 xxxx xxxxxxxxxxxxx 99
>> 99 99 99 xxxx
>> xxxxxxxxxxxxx 99 99
>> 99 99
>
> You could try using common table expressions, which let you build up to
> your final result in steps. Some reading:
>
> http://www.postgresql.org/docs/9.3/static/queries-with.html
>
> http://www.chesnok.com/daily/2013/11/12/how-i-write-queries-using-psql-ctes/
>
>
> Ray.
>
>
> --
> Raymond O'Donnell :: Galway :: Ireland
> rod(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hengky Liwandouw 2013-11-18 10:04:13 Re: Help : Sum 2 tables based on key from other table
Previous Message Ken Tanzer 2013-11-18 09:37:56 Re: Help : Sum 2 tables based on key from other table