From: | e-letter <inpost(at)gmail(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | apply sum function after group by extract month date |
Date: | 2013-09-10 09:02:21 |
Message-ID: | CAET1fe7qxmo+pDTyqTr=3Lz6wyDfHA8tsZqMQWp9QZyTbhPGkA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Readers
How to apply a sum function to rows grouped by date?
create table testgroupsum (itemname varchar(50),date date,amount money);
set datestyle to DMY;
insert into testgroupsum (itemname,date,amount) values ('item
1','2013-01-01','100');
insert into testgroupsum (itemname,date,amount) values ('item
2','2013-01-10','35');
insert into testgroupsum (itemname,date,amount) values ('item
3','2013-02-20','50');
insert into testgroupsum (itemname,date,amount) values ('item
a','2013-01-25','-500');
insert into testgroupsum (itemname,date,amount) values ('item
b','2013-02-28','-20');
drop table testgroupsum;
How to change currency unit for the data type money, i.e. to change
the currency sign from dollar ($) shown in a query result?
The manual states that date data can be extracted, so the following was tried:
select extract (month from (select date from testgroupsum where date >
'2013-01-01'));
ERROR: more than one row returned by a subquery used as an expression
The objective is to be able to apply sum function to items 1 and 2,
grouped by month value = 1. Then to apply a subsequent _net_ sum 1
items 1 and 2, item a, i.e. for month value = 1, compute sum
100,35,-500; month value = 2, compute sum 50,-20; etc.
Thanks in advance.
From | Date | Subject | |
---|---|---|---|
Next Message | James David Smith | 2013-09-10 09:09:22 | Re: apply sum function after group by extract month date |
Previous Message | Tom Lane | 2013-09-07 14:46:36 | Re: Difference in query performance when made from C/C++ client vs. psql client. |