Re: fumbling for join syntax

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Daniel Kelley <dkelley(at)otec(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: fumbling for join syntax
Date: 2002-09-05 15:55:54
Message-ID: web-1634781@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Daniel,

> select triv_a_r.login as user, count(triv_a_r.login) as score,
> sum(triv_a_r.tm)/1000 as time
> from triv_a_r LEFT OUTER JOIN triv_q_r ON (triv_a_r.tq_id =
> triv_q_r.id)
> where triv_a_r.ans = triv_q_r.ans
> group by triv_a_r.login
> order by score desc, time asc;

A little SQL trick:

select triv_a_r.login as user,
SUM(CASE WHEN triv_a_r.ans = triv_q_r.ans THEN 1 ELSE 0 END) as score,
sum(triv_a_r.tm)/1000 as time
from triv_a_r LEFT OUTER JOIN triv_q_r ON (triv_a_r.tq_id =
triv_q_r.id)
group by triv_a_r.login
order by score desc, time asc;

Josh Berkus

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message andres javier garcia garcia 2002-09-05 16:53:40 new calculated column
Previous Message Daniel Kelley 2002-09-05 14:29:55 fumbling for join syntax