pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Perdue <perdue@raccoon.com>
To: pgsql-sql@hub.org
Subject: Stuck on SQL - Any Takers?
Date: Thu, 18 Mar 1999 17:44:26 -0600
Message-ID: <011901be7199$4278a390$0b8c5aa5@timnt.weather.net> (raw)

I have a table where each record has nine player fields, like this:

tbl_teams (
fld_team_no int primary key,
fld_cust_no int,
fld_athlete1 int,
fld_athlete2 int,
fld_athlete3 int,
fld_athlete4 int,
fld_athlete5 int,
fld_athlete6 int,
fld_athlete7 int,
fld_athlete8 int,
fld_athlete9 int
);

I'm trying to build a new table that pulls the related player's name and
points from another table, but it isn't working. I'm getting this error:

ERROR:  create: repeated attribute "fld_player_last"

Is there a better way to write this query?


SELECT
tbl_cust.fld_cust_name,
tbl_zip_codes.fld_zip_code,
tbl_zip_codes.fld_city_name,
tbl_zip_codes.fld_state_short,
tbl_zip_codes.fld_area_code,
tbl_teams.fld_team_no,
tbl_athlete_stats_1.fld_player_last,
tbl_athlete_stats_1.fld_player_first,
tbl_athlete_stats_1.fld_total_points_ytd,
tbl_athlete_stats_2.fld_player_last,
tbl_athlete_stats_2.fld_player_first,
tbl_athlete_stats_2.fld_total_points_ytd,
tbl_athlete_stats_3.fld_player_last,
tbl_athlete_stats_3.fld_player_first,
tbl_athlete_stats_3.fld_total_points_ytd,
tbl_athlete_stats_4.fld_player_last,
tbl_athlete_stats_4.fld_player_first,
tbl_athlete_stats_4.fld_total_points_ytd,
tbl_athlete_stats_5.fld_player_last,
tbl_athlete_stats_5.fld_player_first,
tbl_athlete_stats_5.fld_total_points_ytd,
tbl_athlete_stats_6.fld_player_last,
tbl_athlete_stats_6.fld_player_first,
tbl_athlete_stats_6.fld_total_points_ytd,
tbl_athlete_stats_7.fld_player_last,
tbl_athlete_stats_7.fld_player_first,
tbl_athlete_stats_7.fld_total_points_ytd,
tbl_athlete_stats_8.fld_player_last,
tbl_athlete_stats_8.fld_player_first,
tbl_athlete_stats_8.fld_total_points_ytd,
tbl_athlete_stats_9.fld_player_last,
tbl_athlete_stats_9.fld_player_first,
tbl_athlete_stats_9.fld_total_points_ytd,
(tbl_athlete_stats_1.fld_total_points_ytd+
tbl_athlete_stats_2.fld_total_points_ytd+
tbl_athlete_stats_3.fld_total_points_ytd+
tbl_athlete_stats_4.fld_total_points_ytd+
tbl_athlete_stats_5.fld_total_points_ytd+
tbl_athlete_stats_6.fld_total_points_ytd+
tbl_athlete_stats_7.fld_total_points_ytd+
tbl_athlete_stats_8.fld_total_points_ytd+
tbl_athlete_stats_9.fld_total_points_ytd)
AS fld_team_score

INTO tbl_ranked_teams

FROM
tbl_athlete_stats tbl_athlete_stats_1,
tbl_athlete_stats tbl_athlete_stats_2,
tbl_athlete_stats tbl_athlete_stats_3,
tbl_athlete_stats tbl_athlete_stats_4,
tbl_athlete_stats tbl_athlete_stats_5,
tbl_athlete_stats tbl_athlete_stats_6,
tbl_athlete_stats tbl_athlete_stats_7,
tbl_athlete_stats tbl_athlete_stats_8,
tbl_athlete_stats tbl_athlete_stats_9

WHERE
tbl_athlete_stats_1.fld_player_number = tbl_teams.fld_athlete1 and
tbl_athlete_stats_2.fld_player_number = tbl_teams.fld_athlete2 and
tbl_athlete_stats_3.fld_player_number = tbl_teams.fld_athlete3 and
tbl_athlete_stats_4.fld_player_number = tbl_teams.fld_athlete4 and
tbl_athlete_stats_5.fld_player_number = tbl_teams.fld_athlete5 and
tbl_athlete_stats_6.fld_player_number = tbl_teams.fld_athlete6 and
tbl_athlete_stats_7.fld_player_number = tbl_teams.fld_athlete7 and
tbl_athlete_stats_8.fld_player_number = tbl_teams.fld_athlete8 and
tbl_athlete_stats_9.fld_player_number = tbl_teams.fld_athlete9 and
tbl_teams.fld_cust_no = tbl_cust.fld_cust_no and
tbl_cust.fld_zip = tbl_zip_codes.fld_zip_code

ORDER BY fld_team_score DESC;




view thread (7+ messages)  latest in thread

Message-ID: <011901be7199$4278a390$0b8c5aa5@timnt.weather.net>
Permalink:  ../011901be7199$4278a390$0b8c5aa5@timnt.weather.net/
Also on:    postgresql.org/message-id/011901be7199$4278a390$0b8c5aa5@timnt.weather.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: perdue@raccoon.com, pgsql-sql@hub.org
  Subject: Re: Stuck on SQL - Any Takers?
  In-Reply-To: <011901be7199$4278a390$0b8c5aa5@timnt.weather.net>
  References: <011901be7199$4278a390$0b8c5aa5@timnt.weather.net>

* 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