Re: apply sum function after group by extract month date
| От | e-letter |
|---|---|
| Тема | Re: apply sum function after group by extract month date |
| Дата | |
| Msg-id | CAET1fe5adcVtpwKq3fQcTTzqbrx7LPAQBcji1nCxkgqLGhde2Q@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: apply sum function after group by extract month date (James David Smith <james.david.smith@gmail.com>) |
| Список | 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 по дате отправления: