pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: The Web Administrator <wwwadmin@wizard.ca>
To: PGsql <pgsql-sql@postgreSQL.org>
Subject: Sub Queries
Date: Thu, 23 Jul 1998 21:18:54 -0700
Message-ID: <35B80B2E.CE3B1C3C@wizard.ca> (raw)

I have a little SQL puzzle I am trying to work out..
This is an a/r question...
I have various transactions with date,amount, group, and userid,
(amongst others)

I need to get a query that will return totals as single rows in the
following format

Users | AR current | AR over 30 | AR over 60 | AR over 90 | Total AR

It will be returned grouped by group

User is count( DISTINCT userid)
AR_current is a total of all amounts in the rows whose dates are in this
month..
AR_over 30 is with dates in the preceding month
etc..
And AR_total is the total of all amounts in all the rows of the table.
I am trying to use several subqueries each returning a sum of the
applicable balances

I cannot seem to get it to work.. Any other suggestions on how to handle
this issue?

Table has rows like
userid -- from which I can also get the group
dateposted
amount

Looking for rows returned as
groupa,  number of users with records in this table in this group,
dollar figure who's transactions are in a certain date range(1), dollars
in date range (2), in date range (3), total of all transactions in that
group.
groupb, etc..
groupc, etc..

--
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Michael - System Administrator              Working in Cheap Canadian
Dollars
Unix Administration - WebSite Hosting - Network Services - Programming
Wizard Internet Services - TechnoWizard Computers - Wizard Tower
TechnoServices
------------------------------------------------------------------------------

(604) 589-0037          Beautiful British Columbia, Canada
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++






Message-ID: <35B80B2E.CE3B1C3C@wizard.ca>
Permalink:  ../35B80B2E.CE3B1C3C@wizard.ca/
Also on:    postgresql.org/message-id/35B80B2E.CE3B1C3C@wizard.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: wwwadmin@wizard.ca
  Subject: Re: Sub Queries
  In-Reply-To: <35B80B2E.CE3B1C3C@wizard.ca>
  References: <35B80B2E.CE3B1C3C@wizard.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox