Best database model for canvassing (and analysing) opinion

From: Sebastian Tennant <sebyte(at)smolny(dot)plus(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Best database model for canvassing (and analysing) opinion
Date: 2009-08-18 08:58:12
Message-ID: r5v9bisb.fsf@vps203.linuxvps.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

A school wants to offer a number of short courses on a number of different
dates. Students apply online for a single course at a time and choose one or
more dates (from a list) which would suit them. Once the application period is
over which course is taught when is decided soley on the basis of maximising
the number of students that can attend.

Perhaps the simplest model is a database table 'application_forms' which
includes two text columns; 'course' and 'preferred_dates' with entries that
look like this:

course: "Drama"
prefered_dates: "Sat_22Aug09, Tue_25Aug09, Tue_08Sep09"

The data can then be usefully presented in a series of SELECT statements (one
for each date):

AS SELECT count(*), course FROM application_forms WHERE preferred_dates like
'%Sat_22Aug09%' GROUP BY course ORDER BY count DESC;

count | course
-------+---------
7 | Drama
3 | Readers
1 | Self-study

but clearly this method doesn't scale very well as the number of dates
increases.

A single table of results looking something like this would be far better, but
how?

date | course_suiting_most_applicants | num_applicants
----- ------+--------------------------------+---------------
Sat_22Aug09 | Drama | 7
Tue_25Aug09 | Readers | 4

Any advice/tips/pointers/suggestions for a database design newbie very much
appreciated.

Regards,

Sebastian

--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap

Responses

Browse pgsql-general by date

  From Date Subject
Next Message wstrzalka 2009-08-18 09:16:20 2 versions of Postgres on the same machine
Previous Message Daniel Verite 2009-08-18 08:32:35 Re: comparing NEW and OLD (any good this way?)