Re: Queries and abstraction - longish

From: Roy Hann <specially_at_processed.almost.meat>
Date: Sat, 9 May 2015 11:18:55 +0000 (UTC)
Message-ID: <mikqev$lqi$1_at_speranza.aioe.org>


Joe Thurbon wrote:

> I have a question which comes from a practical issue, but which I think
> has a theoretical aspect.
[snip]

> select
> product_being_identified,
> question_number,
> question_text,
> avg(point_on_scale/size_of_scale) as average_scale
> from
> QUESTIONS
> natural join
> (
> ***
> some query based on RESPONSES and DEMOGRAPHICS
> ***
> ) responses
> natural join ANSWERS
> group by
> product_being_identified,
> question_number,
> question_text;
>
>
> In some sense, all the bits outside the *** in the above query represent
> some sort of abstract processing that happens on "target responses". As
> that bit gets more and more complex, I want to avoid duplicating it.

Since you're doing a natural join with QUESTIONS and ANSWERS, any table with suitably named column(s) can be mentioned in place of your arbitrary query. In your situation I'd probably use a reference to a session temporary table there. I'd declare my session temporary table AS SELECT from RESPONSES and DEMOGRAPHICS just before running the above query.

Roy Received on Sat May 09 2015 - 13:18:55 CEST

Original text of this message