Calculating with sql - Mailing list pgsql-sql

From Dennis Kaarsemaker
Subject Calculating with sql
Date
Msg-id afdeiv.214.1@kaarsemaker.nb.nu
Whole thread Raw
Responses Re: Calculating with sql  (Masaru Sugawara <rk73@sea.plala.or.jp>)
List 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-|\




pgsql-sql by date:

Previous
From: q u a d r a
Date:
Subject: graphical interface - admin
Next
From: "Jörg Holetschek"
Date:
Subject: CHECK clause doesn't work with CASE clause