From: Yasir Malik <ymalik@cs.stevens.edu>
To: PostgreSQL <pgsql-sql@postgresql.org>
Subject: Re: Am I crazy or is this SQL not possible
Date: Thu, 1 Jun 2006 14:13:40 -0400 (EDT)
Message-ID: <Pine.NEB.4.64.0606011409360.758@pink-elephant.cs.stevens-tech.edu> (raw)
In-Reply-To: <df01c91b0606011043g61328d6habaee8fa037a5ccf@mail.gmail.com>
References: <df01c91b0606011043g61328d6habaee8fa037a5ccf@mail.gmail.com>
> What I would like to do is simply get the last date_sent and it's
> status for every broadcast. I can't do a GROUP BY because I can't put
> an aggregate on the status column.
>
> SELECT MAX(date_sent), status
> FROM broadcast_history
> GROUP BY broadcast_id
>
You could try the following:
select status
from broadcast_history bh
where bh.date_sent =
(select max(bh2.date_sent)
from broadcast_history bh2);
This reminds me of an interview question: I was asked how to get a
maximum column from a table without using max. How would you do that?
Thanks,
Yasir
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: ymalik@cs.stevens.edu
Subject: Re: Am I crazy or is this SQL not possible
In-Reply-To: <Pine.NEB.4.64.0606011409360.758@pink-elephant.cs.stevens-tech.edu>
References: <df01c91b0606011043g61328d6habaee8fa037a5ccf@mail.gmail.com> <Pine.NEB.4.64.0606011409360.758@pink-elephant.cs.stevens-tech.edu>
* 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