Advertisement
thebys

I - celorepublikové výsledky

May 29th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.29 KB | None | 0 0
  1. /*poměrný systém, celorepublikový volební obvod*/
  2. declare @cenamandatu int;
  3. declare @rokvoleb int;
  4. declare @rozdelenomandatu bigint;
  5. declare @platnychhlasu int;
  6. select @rokvoleb = 1996;
  7. select @platnychhlasu = SUM(dbo.results.Votes) from dbo.Results where dbo.results.subjectid is not null and year = @rokvoleb;
  8. select @cenamandatu = @platnychhlasu / 200  from dbo.Results where dbo.results.subjectid is not null and year = @rokvoleb;
  9. select @platnychhlasu as "platných hlasů", @cenamandatu as "cena mandátu", @rokvoleb as "rok voleb", @rozdelenomandatu as "rozděleno mandátů (přirozeně)", 200-@rozdelenomandatu as "mandátů zbývá";
  10. /*rok - počet hlasů celorepublikově - zkratka strany*/
  11. select sum(dbo.results.votes) as "počet hlasů celorepublikově",
  12.  dbo.Subjects.abbreviation as "zkratka strany",
  13.   (sum(dbo.results.votes)/@cenamandatu) as "počet mandátů",
  14.   (@cenamandatu*(sum(dbo.results.votes)/@cenamandatu)) as "hlasů připočítáno",
  15.     (sum(dbo.results.votes)-(@cenamandatu*(sum(dbo.results.votes)/@cenamandatu))) as "hlasů nepřepočítáno"
  16.   from dbo.Results, dbo.Subjects
  17.    where dbo.results.subjectid = dbo.subjects.subjectid
  18.     and results.year = @rokvoleb
  19.     and results.subjectid is not null
  20.      group by dbo.results.year, dbo.subjects.abbreviation;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement