From: A.M. <agentm@cmu.edu>
To: pgsql-sql@postgresql.org
Subject: Getting the latest unique items
Date: Wed, 11 Dec 2002 13:15:34 -0500
Message-ID: <8A486724-0D34-11D7-BA9C-0030657192DA@cmu.edu> (raw)
I have a table as follows:
CREATE TABLE student_gradedmaterial(
id SERIAL,
studentid INT8 REFERENCES student,
gradedmaterialid INT8 REFERENCES gradedmaterial,
caid INT8 REFERENCES ca,
...
submittime TIMESTAMP,
gradedtime TIMESTAMP,
score INT4
);
Every time a student submits a homework, one new entry in the table is
created. I know how to grab the latest version based on the submittime
but naturally, I'd like to be able to count how many homeworks are
graded and ungraded (ungraded means score is NULL). This smells of a
subselect:
graded (grab row count):
SELECT UNIQUE id FROM student_gradedmaterial WHERE EXISTS (SELECT the
latest unique submissions);
or:
SELECT COUNT(score) FROM student_gradedmaterial WHERE
gradedmaterialid=X AND submittime = MAX(SELECT submittime FROM
student_gradedmaterial WHERE gradedmaterialid=X);
(Sub-selects just make my head explode.) Any hints for me? Thanks.
><><><><><><><><><
AgentM
agentm@cmu.edu
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: agentm@cmu.edu
Subject: Re: Getting the latest unique items
In-Reply-To: <8A486724-0D34-11D7-BA9C-0030657192DA@cmu.edu>
References: <8A486724-0D34-11D7-BA9C-0030657192DA@cmu.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