Re: apply sum function after group by extract month date - Mailing list pgsql-novice

From e-letter
Subject Re: apply sum function after group by extract month date
Date
Msg-id CAET1fe5adcVtpwKq3fQcTTzqbrx7LPAQBcji1nCxkgqLGhde2Q@mail.gmail.com
Whole thread Raw
In response to Re: apply sum function after group by extract month date  (James David Smith <james.david.smith@gmail.com>)
List pgsql-novice
On 10/09/2013, James David Smith <james.david.smith@gmail.com> wrote:
> Hey there,
>
> Is this what you are after? Note that I've changed the 'money' type to
> numeric.
>

Why did you change the data type? Answered my own question by changing
the data type to numeric as you did:

 date_part | ?column?
-----------+----------
         1 | £-730
         2 | £60
(2 rows)

The position of the negative sign (-) is wrong; presumably this a
consequence of the 'numeric' data type that cannot be changed?

The extract function:
>
> SELECT EXTRACT(month FROM(date)), SUM(amount) FROM testgroupsum GROUP
> BY EXTRACT(month FROM(date));
>

returns:

 date_part |   sum
-----------+----------
         1 | -$365.00
         2 |   $30.00
(2 rows)

> -- Then if you want to put an dollar or whatever you could do this:
>
> SELECT EXTRACT(month FROM(date)), '£' || SUM(amount) FROM testgroupsum
> GROUP BY EXTRACT(month FROM(date));
>

returns:

 date_part |  ?column?
-----------+------------
         1 | £-$365.00
         2 | £$30.00
(2 rows)


pgsql-novice by date:

Previous
From: James David Smith
Date:
Subject: Re: apply sum function after group by extract month date
Next
From: James David Smith
Date:
Subject: Running two queries concurrently?