pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Daniel Kelley <dkelley@otec.com>
To: pgsql-sql@postgresql.org
Subject: Re: fumbling for join syntax
Date: Thu, 05 Sep 2002 08:55:54 -0700
Message-ID: <web-1634781@davinci.ethosmedia.com> (raw)
In-Reply-To: <Pine.BSF.4.20L2.0209051002120.7508-100000@mx1.gc.ny.otec.com>

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



view thread (2+ messages)

Message-ID: <web-1634781@davinci.ethosmedia.com>
Permalink:  ../web-1634781@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-1634781@davinci.ethosmedia.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, dkelley@otec.com
  Subject: Re: fumbling for join syntax
  In-Reply-To: <web-1634781@davinci.ethosmedia.com>

* 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