All pastes #574306 Raw Edit

snoyes

public text v1 · immutable
·published 2007-06-18 14:43 UTC
rendered paste body

mysql> SELECT pfd.pf_score, pfd.pf_played_games, pfd.pf_score / pfd.pf_played_games FROM phpbb_users u , phpbb_profile_fields_data pfd WHERE u.user_type IN (0, 3) AND u.user_id = pfd.user_id ORDER BY pfd.pf_score = 0, pfd.pf_played_games / IF(pfd.pf_score = 0, 1, pfd.pf_score) ASC LIMIT 10;
+----------+-----------------+------------------------------------+
| pf_score | pf_played_games | pfd.pf_score / pfd.pf_played_games |
+----------+-----------------+------------------------------------+
|     -100 |               6 |                           -16.6667 |
|     -200 |               8 |                           -25.0000 |
|     -150 |               6 |                           -25.0000 |
|     -300 |               8 |                           -37.5000 |
|   127310 |             400 |                           318.2750 |
|      300 |               1 |                           300.0000 |
|   159300 |             592 |                           269.0878 |
|   856000 |            3237 |                           264.4424 |
|    36390 |             151 |                           240.9934 |
|    67000 |             278 |                           241.0072 |
+----------+-----------------+------------------------------------+


--------------


mysql> SELECT * FROM scores;
+--------+-------+
| score  | games |
+--------+-------+
|   -100 |     6 |
|   -200 |     8 |
| 127310 |   400 |
+--------+-------+
3 rows in set (0.00 sec)

mysql> SELECT *, round(score / games) FROM scores ORDER BY games = 0, score / games DESC;
+--------+-------+----------------------+
| score  | games | round(score / games) |
+--------+-------+----------------------+
| 127310 |   400 |                  318 |
|   -100 |     6 |                  -17 |
|   -200 |     8 |                  -25 |
+--------+-------+----------------------+
3 rows in set (0.00 sec)