Blog for Learning

| lesson material | material summary | questions and answers | definitions | types and examples | other information | materi pelajaran | ringkasan materi | pertanyaan dan jawaban | definisi | jenis-jenis dan contoh-contoh | informasi lainnya |

Powered by Blogger.

Pages

MySQL Query to Determine Winners

Mysql query to determine the winner on the E-Voting system
I am developing a web application for the selection of the BEM chairman with the CodeIgniter framework. This application is almost complete. However, there is one thing that still makes me confused, namely determining the winner after the election is finished.
The first query - in my opinion appropriate - obtained from a search on Google is as follows:
SELECT
    calon_idcalon,
    calon.nama AS nama,
    calon.foto AS foto,
    COUNT(calon_idcalon) AS jumlah
FROM
    kotak_suara,
    calon
WHERE
    calon_idcalon = calon.nim
GROUP BY calon_idcalon
ORDER BY jumlah
DESC LIMIT 1
The results obtained from the query are one person with the highest number of votes. But, how about if there are two people who have the most sura.
When using the above query, the results remain one person.
Finally, I was given a powerful query from one of the MySQL Indonesia member groups . This powerful query can display all winners with the same vote.
SELECT
    calon_idcalon,
    calon.nama AS nama,
    calon.foto AS foto,
    COUNT(calon_idcalon) AS jumlah
FROM
    kotak_suara,
    calon
WHERE
    calon_idcalon = calon.nim
GROUP BY
    calon_idcalon
HAVING
    COUNT( calon_idcalon) >= (
        SELECT COUNT( calon_idcalon ) AS SUM
        FROM kotak_suara
        GROUP BY calon_idcalon
        ORDER BY SUM
        DESC LIMIT 1
    )
The winner selected from the query results
0 Komentar untuk "MySQL Query to Determine Winners"

Silahkan berkomentar sesuai artikel

 
Template By Kunci Dunia
Back To Top