From: | e-letter <inpost(at)gmail(dot)com> |
---|---|
To: | James David Smith <james(dot)david(dot)smith(at)gmail(dot)com> |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: apply sum function after group by extract month date |
Date: | 2013-09-10 09:56:27 |
Message-ID: | CAET1fe5adcVtpwKq3fQcTTzqbrx7LPAQBcji1nCxkgqLGhde2Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On 10/09/2013, James David Smith <james(dot)david(dot)smith(at)gmail(dot)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)
From | Date | Subject | |
---|---|---|---|
Next Message | James David Smith | 2013-09-10 14:54:58 | Running two queries concurrently? |
Previous Message | James David Smith | 2013-09-10 09:09:22 | Re: apply sum function after group by extract month date |