Last active
June 6, 2016 08:01
-
-
Save marciuz/26e832bf700be391ad0b238fb6d5dce3 to your computer and use it in GitHub Desktop.
Esempi postgresql 3 candidati
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Esempio con 3 candidati. | |
-- Viene codificato con (1,2,3) il candidato con la maggioranza nella sezione. | |
-- In caso di parità sulla percentuale (arrotondata con 0 decimali), restituisce 0. | |
-- | |
SELECT | |
CASE | |
WHEN (de_magistris > lettieri AND de_magistris > morcone) THEN 1 | |
WHEN (lettieri > de_magistris AND lettieri > morcone) THEN 2 | |
WHEN (morcone > de_magistris AND morcone > lettieri) THEN 3 | |
ELSE 0 | |
END AS piu_votato, | |
t1.* | |
FROM napoli_amm2011_sindaco t1; | |
-- | |
-- Esempio con arrotondamento al 2%, per diminuire lo scarto entro il quale considerare "patta" una sezione. | |
-- | |
SELECT | |
CASE | |
WHEN (ROUND(de_magistris/2) > ROUND(lettieri/2) AND ROUND(de_magistris/2) > ROUND(morcone/2)) THEN 1 | |
WHEN ((lettieri/2) > (de_magistris/2) AND (lettieri/2) > ROUND(morcone/2)) THEN 2 | |
WHEN ((morcone/2) > (de_magistris/2) AND ROUND(morcone/2) > (lettieri/2)) THEN 3 | |
ELSE 0 | |
END AS piu_votato, | |
t1.* | |
FROM napoli_amm2011_sindaco t1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Infowindow --> | |
<div class="cartodb-popup v2 custom_infowindow"> | |
<a href="#close" class="cartodb-popup-close-button close">x</a> | |
<div class="cartodb-popup-content-wrapper"> | |
<div class="row"> | |
<div class="label"></div> | |
<div class="xinfo"> | |
<b>Sezione:</b> {{sezione}}<br> | |
<b>Via:</b> {{indirizzo}}<br><br> | |
<img src="http://chart.googleapis.com/chart?chs=250x100&chd=t:{{voti_esposito}},{{voti_amura}},{{voti_lettieri}},{{voti_prudente}},{{voti_brambilla}},{{voti_alboreto}},{{voti_mercogliano}},{{voti_taglialatela}},{{voti_de_magistris}},{{voti_valente}}&cht=p&chl=Esposito|Amura|Lettieri|Prudente|Brambilla|Alboreto|Mercogliano|Taglialatela|De_Magistris|Valente&chco=0A6600|841E23|205DA0|990000|ECAE28|4FA09A|DFDFDF|22345D|E84E1A|C9242E" width="250" height="100" /> | |
<br><br> | |
<b>De Magistris:</b> {{perc_de_magistris}}% ({{voti_de_magistris}})<br> | |
<b>Lettieri:</b> {{perc_lettieri}}% ({{voti_lettieri}})<br> | |
<b>Valente:</b> {{perc_valente}}% ({{voti_valente}})<br> | |
<b>Tot sezione:</b> {{tot_validi}} voti<br><br> | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Legenda --> | |
<div class='cartodb-legend custom'> | |
<div class="legend-title">LEGENDA</div> | |
<ul> | |
<li> | |
<div class="bullet" style="background:#FFFFFF"></div> | |
DATI NON disponibili | |
</li> | |
<li> | |
<div class="bullet" style="background:#FF9900"></div> | |
Maggioranza De Magistris | |
</li> | |
<li> | |
<div class="bullet" style="background:#205da0"></div> | |
Maggioranza Lettieri | |
</li> | |
<li> | |
<div class="bullet" style="background:#c9242e"></div> | |
Maggioranza Valente | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment