pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Janning Vygen <janning@vygen.de>
To: Masaru Sugawara <rk73@sea.plala.or.jp>
Cc: pgsql-sql@postgresql.org
Subject: Re: Joining three data sources.
Date: Wed, 19 Jun 2002 20:07:20 +0200
Message-ID: <02061920072002.26278@konkordia> (raw)
In-Reply-To: <20020619230842.91E2.RK73@sea.plala.or.jp>
References: <200206191033.g5JAXnX19714@janning.planwerk6.local>
	<20020619230842.91E2.RK73@sea.plala.or.jp>

Am Mittwoch, 19. Juni 2002 16:09 schrieb Masaru Sugawara:
> On Wed, 19 Jun 2002 12:33:47 +0200
>
> Janning Vygen <vygen@gmx.de> wrote:
> > ---------------------
> > Result Inter Mailand vs. AC ROM 2:1
> > team1_id|team2_id|goals1|goals2
> >   1         2       2      1
>
> SELECT go1.game_id, go1.team1_id, go1.team2_id,
>           SUM(CASE WHEN go2.team_id = go1.team1_id
>                      THEN go2.n ELSE 0 END) AS goals1,
>           SUM(CASE WHEN go2.team_id = go1.team2_id
>                      THEN go2.n ELSE 0 END) AS goals2
> FROM  (SELECT game_id,
>                     min(team_id) AS team1_id,
>                     max(team_id) AS team2_id
>               FROM goal
>             GROUP BY 1) AS go1,
>           (SELECT game_id, team_id, count(*) AS n
>                FROM goal
>             GROUP BY 1, 2) AS go2
> WHERE go1.game_id = go2.game_id
> GROUP BY 1, 2, 3;

Oh thanks  a lot. You pushed me in the right direction. i still get headache 
when trying to write complicated selects. there was something wrong in your 
statement but i was able to correct it by myself. Thanks for your help!!

Are you able to type those queries in minutes?? It seems so ... amazing! 

> As for Goal table, if it has a large number of the rows, you maybe
> need to create a unique index on it.

of course. it was just an example...

kind regards 
janning



view thread (5+ messages)  latest in thread

Message-ID: <02061920072002.26278@konkordia>
Permalink:  ../02061920072002.26278@konkordia/
Also on:    postgresql.org/message-id/02061920072002.26278@konkordia

 · 

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: janning@vygen.de, rk73@sea.plala.or.jp
  Subject: Re: Joining three data sources.
  In-Reply-To: <02061920072002.26278@konkordia>

* 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