pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargentg <robjsargent@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Presenting data in 5 Rows & 5 Cols for 25 specific values
Date: Sun, 04 Aug 2013 22:01:15 -0600
Message-ID: <51FF238B.1080707@gmail.com> (raw)
In-Reply-To: <CAAmqg_BorkCvgY2NzAYkr=9ysrzswOGTtKdtsZ5H4MCpHj5ZVw@mail.gmail.com>
References: <CAAmqg_BorkCvgY2NzAYkr=9ysrzswOGTtKdtsZ5H4MCpHj5ZVw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

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



view thread (3+ messages)

Message-ID: <51FF238B.1080707@gmail.com>
Permalink:  ../51FF238B.1080707@gmail.com/
Also on:    postgresql.org/message-id/51FF238B.1080707@gmail.com

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: robjsargent@gmail.com
  Subject: Re: Presenting data in 5 Rows & 5 Cols for 25 specific values
  In-Reply-To: <51FF238B.1080707@gmail.com>

* 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