jeudi 16 juin 2016

Selection based on Ranking and Weighting in MySQL

How do I select a rank of countries based on number of medals won by measuring the number of Gold(3), silver(2), Bronze(1) from the table below:

+-----------+-------------+--------+-----------------+----------------------------+-------------------------------+-----------------------------------------+---------------------------------+-------------------------+
| idRESULTS | STATUS      | MEDALS | EVENTS_idEVENTS | EVENTS_ATHLETES_idATHLETES | EVENTS_ATHLETES_TEAMS_idTEAMS | EVENTS_ATHLETES_TEAMS_COUNTRY_idCOUNTRY | EVENTS_VARIOUS_SPORTS_SPORTS_ID | awarded_medals_medal-id |
+-----------+-------------+--------+-----------------+----------------------------+-------------------------------+-----------------------------------------+---------------------------------+-------------------------+
| results1  | DID-NOT-WIN | SILVER | TEN             | MS                         | RUS-WTA                       | RUS                                     | WOMENS_TENNIS                   |                       2 |
| results1  | WON         | GOLD   | TEN             | VW                         | USA-WTA                       | USA                                     | WOMENS_TENNIS                   |                       3 |
| results2  | DID-NOT-WIN | BRONZE | ATH             | JG                         | USA-TF-MEN                    | USA                                     | TRACK-AND-FIELD                 |                       3 |
| results2  | WON         | GOLD   | ATH             | UB                         | JAM-TF-MEN                    | JAM                                     | TRACK-AND-FIELD                 |                       1 |
| results3  | WON         | GOLD   | TEN-DOUBLE      | SW                         | USA-WTA                       | USA                                     | WOMENS_TENNIS                   |                       3 |
| results3  | WON         | GOLD   | TEN-DOUBLE      | VW                         | USA-WTA                       | USA                                     | WOMENS_TENNIS                   |                       1 |
+-----------+-------------+--------+-----------------+----------------------------+-------------------------------+-----------------------------------------+---------------------------------+-------------------------+

I have this code below but this does not produce the expected output?

select EVENTS_ATHLETES_TEAMS_COUNTRY_idCOUNTRY,MEDALS
 from results
 group by EVENTS_ATHLETES_TEAMS_COUNTRY_idCOUNTRY

Aucun commentaire:

Enregistrer un commentaire