From: Peter Brawley Date: April 11 2006 2:55pm Subject: Re: Making result rows to one row List-Archive: http://lists.mysql.com/mysql/196775 Message-Id: <443BC35A.7080907@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Peter, > Peter Brawley said: > > SELECT > ..., > GROUP CONCAT(LPAD(strokes,3,' ') SEPARATOR '') AS ' 1 2 3 4 5 6 7 > 8 9' > FROM tour_player_score tps > INNER JOIN tour_scorecard_hole tsh ON tps.scorecard_hole_id=tsh.id > WHERE tour_player_id=175 > GROUP BY tsh.id > > This worked, however, it gives me all results in one cell. I would like to > have them sorted in one cell per strokes. Is that possible? Sure, that's what the pivot table example at http://www.artfulsoftware.com/queries.php#36 does. Your query would be something like... SELECT player_id, MAX( IF(hole=1,strokes,'') ) AS 'Hole 1' MAX( IF(hole=2,strokes,'') ) AS 'Hole 22, ... FROM tbl GROUP BY player_id ... PB > The reason for > this is that I have to use each hole as ORDER criteria. If the SUM is equal, > then I have to check the sum of the last nine holes. If they are the same, > then I have to check the result of hole 18, 17, 16 etc. > > This is my exact query as is now: > > SELECT tps.tour_player_id, GROUP_CONCAT(LPAD(strokes,2,' ') SEPARATOR '-') > AS hole_scores, sum(tps.strokes) AS 'score' FROM tour_player_score tps INNER > JOIN tour_scorecard_hole tsh ON tps.scorecard_hole_id=tsh.id GROUP BY > tps.tour_player_id ORDER BY score; > > Best regards, > Peter Lauri > > > > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.385 / Virus Database: 268.4.0/306 - Release Date: 4/9/2006