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

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: (view raw, whole thread or download thread mbox)
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?

pgsql-novice by date

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

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