Calculating with sql

From: Dennis Kaarsemaker <fake_adress(at)use-reply(dot)to>
To: pgsql-sql(at)postgresql(dot)org
Subject: Calculating with sql
Date: 2002-06-26 20:18:07
Message-ID: afdeiv.214.1@kaarsemaker.nb.nu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm having trouble figuring out how to select something.
This is the problem:

From a copy of the CDDB-database i want to select the artist & album that
has on average the longest tracks.

But in the tracks table there is no such field as length, so i have to
calculate it. But when i try to do so it just gives me errors.

This is the erroneous query i have made so far

select albums.ARTIST, albums.TITLE from tracks,albums
where tracks.DISCID = albums.DISCID
group by tracks.DISCID
having(albums.LENGTH/count(tracks.TRACK)) =
(
select max(albums.LENGTH/count(tracks.TRACK)) from tracks,albums
where tracks.DISCID = albums.DISCID
group by tracks.DISCID
);

What is the correct way of selecting the album?
--
Dennis K.
~.. It is impossible to make anything foolproof,
.>>. because fools are so ingenious -Roger Berg-
|\

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-06-26 22:59:04 Re: Possibility of Index-Only access in PostgreSQL?
Previous Message Josh Berkus 2002-06-26 18:12:02 Re: Limiting database size