Skip site navigation (1) Skip section navigation (2)

Re: Is it possible in PostgreSQL?

From: "jim(dot)bagley(at)traderonline(dot)com" <jim(dot)bagley(at)traderonline(dot)com>
To: Bronx <tobronx(at)go2(dot)pl>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Is it possible in PostgreSQL?
Date: 2004-01-16 18:10:11
Message-ID: 40082903.2060909@traderonline.com (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-sql
In Oracle you can use cursors as columns.  not sure if that will work in 
postgresql.  never tried it.  =)

ex:

select name, curosr(select sum(quantity) from tablename where date 
between(pick a date) and (pick another date)) as 01,
    curosr(select sum(quantity) from tablename where date between(pick a 
date) and (pick another date)) as 02,
    curosr(select sum(quantity) from tablename where date between(pick a 
date) and (pick another date)) as 03,
from tablename;


thanks should give you the output you described below.  Again, I am not 
sure if this is SQL Standard or just a function that Oracle offers.

jim

Bronx wrote:

> Hi,
> I've got problem with one specific query. I've got the table
> with many of rekords like these:
>  
> name     |  quantity    | date
> -------------------------------------------------------
> aaa            2                2003-04-01
> bbb            4                2003-04-12
> ccc            5                2003-05-12
> aaa            3                2003-01-14
> aaa            1                2003-12-09
> bbb            9                2003-08-08
>  
> and so on ...
>  
> Does anybody know how make query which return grouped
> records by month of year and name (also sum of quantity).
> It is possible to make a query whitch return something like that:
>  
> name | 01 | 02 | 03 | 04 | ... | 12 (months)
> ------------------------------------------------
> aaa     x     x     x    x    ...   x
> bbb     x     x     x    x    ...   x
> ccc     x     x     x    x    ...   x
>  
> where x means sum of quantity in month.
> It is possible to make it in one query?
> I know that in Access is construction : PIVOT.
>  
> Thanks
> Adam
>  


-- 

Jim Bagley
Database Manager
Trader Electronic Media
(757) 321-8409 (work)
(757) 343-1768 (cell)

www.Employmentguide.com <http://www.employmentguide.com> - Bringing 
Employers and Jobseekers Together.
www.ForRent.com <http://www.forrent.com> - Nation's Leading Apartment 
Rental Source.
www.HarmonHomes.com <http://www.harmonhomes.com> - Your Home Site on the 
Web.
www.ParenthoodWeb.com <http://www.parenthoodweb.com> - Pregnancy and 
Parenting Advice, Baby Names and More.
www.Roomsaver.com <http://www.roomsaver.com> - 6000+ Lodging Coupons.
www.TraderOnline.com <http://www.traderonline.com> - Boats, RVs, 
Collector Cars, Motorcycles and More.

 

In response to

pgsql-admin by date

Next:From: Goulet, DickDate: 2004-01-16 19:33:52
Subject: Re: How to manage/tune PostGres
Previous:From: scott.marloweDate: 2004-01-16 17:40:37
Subject: Re: Trouble connecting

pgsql-sql by date

Next:From: LizaDate: 2004-01-16 18:44:35
Subject: simple tree in postgress
Previous:From: Philippe LangDate: 2004-01-16 13:03:26
Subject: Re: sql query with join and parameter in postgresql function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group