Stuck on SQL - Any Takers? - Mailing list pgsql-sql
From | Tim Perdue |
---|---|
Subject | Stuck on SQL - Any Takers? |
Date | |
Msg-id | 011901be7199$4278a390$0b8c5aa5@timnt.weather.net Whole thread Raw |
List | pgsql-sql |
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;