Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can see two options.</p> <p><strong>1) Dealing with it in the application</strong>. The following query will perform neccesary aggregation in the database and return 4 rows for each date_audience (one for each value of quality_apuration). </p> <pre><code>select date_audience ,quality_apuration ,count(*) from pp_base where date_audience &gt;= date '2011-01-01' and date_audience &lt;= date '2011-02-28' group by date_audience ,quality_apuration order by date_audience ,quality_apuration; </code></pre> <p>This is preferred when you expect changes to the quality_apuration values.</p> <p><strong>2) Dealing with it in the database</strong>. You could define a view like the following:</p> <pre><code>create or replace view pp_view as select date_audience ,sum(case when quality_apuration = '1' then 1 else 0 end) as very_good ,sum(case when quality_apuration = '2' then 1 else 0 end) as good ,sum(case when quality_apuration = '3' then 1 else 0 end) as bad ,sum(case when quality_apuration = '4' then 1 else 0 end) as no_apuration ,count(quality_apuration) as total from pp_base group by date_audience; </code></pre> <p>...from the application you would then select as follows:</p> <pre><code>select ... from pp_view where date_audience &gt;= date '2011-01-01' and date_audience &lt;= date '2011-02-28' order by date_audience; </code></pre> <p>Of course, whenever you add another value for quality_apuration, you would have to modify the view definition. Still, it's better than modifying all queries.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload