| From: | Harry <h3(at)x-maru(dot)org> |
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org |
| Subject: | aggregating into 2 dimensions? |
| Date: | 2002-12-08 01:10:34 |
| Message-ID: | 20021207171034.2162120e.h3@x-maru.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
I'd like to perform a query that aggregates/counts based on 2 of my columns.
For example, with a table with 3 columns "date","dept","item", I'd like to get
counts of "item" grouped by "date" and "dept" so that I get a tablular result
such as:
date | deptA | deptB | deptC | ...
------------+------------------------------
2001-05-28 | 10 | 231 | 123 | ...
Basically, something like "select date,dept,count(item) from table group by
date,dept" except giving the results in 2 dimensions, with individual depts as
columns and perhaps a column for a total.
Is this something that can be done with basic SQL (without using functions)?
The number of depts is small and fixed, if that matters.
Thanks,
Harry
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Pucher | 2002-12-08 21:38:40 | Concatenate two tables |
| Previous Message | Oliver Elphick | 2002-12-07 07:53:53 | Re: Test to see if currval will fail? |