Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Bz4-00076k-Fw for pgsql-sql@arkaria.postgresql.org; Mon, 05 Aug 2013 04:01:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V6Bz3-0002eP-WE for pgsql-sql@arkaria.postgresql.org; Mon, 05 Aug 2013 04:01:26 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Bz1-0002eG-L4 for pgsql-sql@postgresql.org; Mon, 05 Aug 2013 04:01:23 +0000 Received: from mail-oa0-x22e.google.com ([2607:f8b0:4003:c02::22e]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6Byy-0000n3-68 for pgsql-sql@postgresql.org; Mon, 05 Aug 2013 04:01:22 +0000 Received: by mail-oa0-f46.google.com with SMTP id l10so5163872oag.19 for ; Sun, 04 Aug 2013 21:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=NMTM32aT6dF+0y/IkfG2bYaDoy5p7ptQVOCtnkJLdXI=; b=QxnxBovYPeQMm+Zum6C+gDUpZIDKbdKioevJqvOOZazcir7k6U7VjLRxocd1GuvB/W 2XRQQl5uO9pKyMAwwVNl6kdBHBQNx+z73X0RsfRCYRxeBKsjQDlJWMrS9stvuT7b1MC8 TZpZS+HJa/HeOBakQj05PfrMNOu0O5BFCWP+AnHy9LDQ4kdRU2BGXRMr9kl9ZsQr2dSk UjL54nHZiAeZR/4RDkfEZyD1ej+Vch9DyqBBdItuXA+tDLOmp/JFbt9O8imOOD7gBaTo AxzuhRGxhrhIXnsqlvbNhg9s3l7Lm/p0x7Yfd0RgVqceMgjgefZYESzmilY4C5aeEbjv y5SQ== X-Received: by 10.50.70.34 with SMTP id j2mr896510igu.42.1375675279089; Sun, 04 Aug 2013 21:01:19 -0700 (PDT) Received: from ?IPv6:2601:7:7a80:0:c4d5:4af9:1076:a603? ([2601:7:7a80:0:c4d5:4af9:1076:a603]) by mx.google.com with ESMTPSA id hb6sm43410igb.8.2013.08.04.21.01.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 04 Aug 2013 21:01:18 -0700 (PDT) Message-ID: <51FF238B.1080707@gmail.com> Date: Sun, 04 Aug 2013 22:01:15 -0600 From: Rob Sargentg User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Presenting data in 5 Rows & 5 Cols for 25 specific values References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 08/03/2013 07:26 AM, F Bax wrote: > I have a table containing tasks completed in a game I'm playing. The > game includes an extra BINGO Challenge where each cell of standard > BINGO card contains a particular task to be completed. The goal is > score a BINGO (row, column, diagonal) by completing five (or more) > tasks from the BINGO cards. My task table contains more tasks > completed than the one included in the BINGO challenge. > > SELECT task, CASE WHEN task='Task27' THEN 'R1C1' WHEN task='Task32' > THEN 'R1C2' ... WHEN task='Task94' THEN 'R5C5' END AS bingo FROM tasks > WHERE bingo IS NOT NULL; > > This query will retrieve all tasks related to the BINGO that I have > completed and present them in a simple list. I would like to arrange > the tasks as a BINGO card; so that I can easily see my progress on > various rows & columns working toward a BINGO. > > Any suggestions? > > BONUS points will be awarded if the query displays a row with 5 NULL > values if no tasks are completed in that row. I haven't noticed any posting showing your exact table definition, but here's more still running on my assumptions and short-cuts. Of course this would all be trivial if the data were sucked into any reasonable language adn delt with there for shipment to the UI. Adding this list of accomplished tasks (the first diagonal) insert into bingo values ('bingo','rjs','task0',0, 0), ('bingo','rjs','task6',1, 1), ('bingo','rjs','task12',2, 2), ('bingo','rjs','task18',3, 3), ('bingo','rjs','task24',4, 4) ; \pset null 'not done'-- you'll probably need to use outer joins and to coalesce null values. select r,c, (select task from bingo i where c = 0 and username = 'rjs' and i.task = b.task and mod(r,5) = 0) as "B", (select task from bingo i where c = 1 and username = 'rjs' and i.task = b.task and mod(r,5) = 1) as "I", (select task from bingo i where c = 2 and username = 'rjs' and i.task = b.task and mod(r,5) = 2) as "N", (select task from bingo i where c = 3 and username = 'rjs' and i.task = b.task and mod(r,5) = 3) as "G", (select task from bingo i where c = 4 and username = 'rjs' and i.task = b.task and mod(r,5) = 4) as "O" from bingo b where username = 'rjs' ; r | c | B | I | N | G | O ---+---+----------+----------+----------+----------+---------- 0 | 0 | task0 | not done | not done | not done | not done 1 | 1 | not done | task6 | not done | not done | not done 2 | 2 | not done | not done | task12 | not done | not done 3 | 3 | not done | not done | not done | task18 | not done 4 | 4 | not done | not done | not done | not done | task24 (5 rows) -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql