c# - What is the right syntax on how to count the votes -


this code used count number of students voted.

select candidate,position, count(studentnumber) 'candidate votes' dbvotingsystem.votes organization = 'isite' group candidate order position; 

the image sample of data in table.

enter image description hereom/cwvst.png

if winner max candidate votes in each group, secretary's winner should many, check following sql:

select     position,     substring_index(group_concat(candidate order `candidate votes` desc), ',', 1) winner,     max(`candidate votes`) `candidate votes` (     select candidate, position, count(studentnumber) 'candidate votes'     dbvotingsystem.votes     organization = 'isite'     group candidate ) votes group position 

result:

|    position | winner | candidate votes | |-------------|--------|-----------------| |   president | audrey |               7 | |   secretary |   many |               8 | |   treasurer |  barry |              10 | | v.president |   juan |               9 | 

demo in sqlfiddle.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -