SubQuery Question

From: "Van Ingen, Lane" <lvaningen(at)ESNCC(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: SubQuery Question
Date: 2005-06-08 20:15:53
Message-ID: A3FF4275060B76459B5C08A64AE330C805C3F9@twmail.esncc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I am trying to make a query and subquery work, but no luck with the query.

In the sample query below, I want to get a count of the number of different car models that
have been sold during a specified period of time. The subquery below works fine. Since I am
using this in a stored procedure, I want to select the count of values returned by the subquery
below ainto a variable and work more with it.

How do I put a count wrapper around the subquery enclosed in parenthesis below ?

select into <count-variable> count(*) .. where ...
(select distinct auto_model from car_lot
where date_sold between '2005-01-01 00:00:00' and '2005-01-31 23:59:59') ;

It seems like I should be able to do this is with one SQL statement.

I considered inserting the sub-query answer into a temp table, then counting the records in the
temp table, but don't want to incur the I/O. If I could stuff it into an array, then count the array, that
would work also, but not sure how to do that.

Does anyone have any thoughts?

Browse pgsql-novice by date

  From Date Subject
Next Message Aarni Ruuhimäki 2005-06-09 09:57:01 Re: CRON Jobs and Backups
Previous Message Razvan Costea-Barlutiu 2005-06-08 17:02:21 Re: Timestamp trouble