Jom Jom - 3 years ago 222
MySQL Question

MYSQL: Return row with minimum number (divided from two columns)

I am trying to find a row if the result inside SQL command is having minimum number, it would be (hour/job):

John: 4
Eve: 0.8571428571
Adam: 1.67
, so the return row would be Eve since it has the lowest value.

table: office



+----+-------+------+------+
| id | name | hour | job |
+----+-------+------+------+
| 1 | John | 8 | 2 |
| 2 | Eve | 6 | 7 |
| 3 | Adam | 5 | 3 |
+----+-------+------+------+


sql



SELECT *
FROM office
WHERE MIN(hour/job)
LIMIT 1





result



+----+-------+------+------+
| id | name | hour | job |
+----+-------+------+------+
| 2 | Eve | 6 | 7 |
+----+-------+------+------+

Answer Source

While its not clear what your question is, it seems the SQL you provided is not working and thats what you want, if so, you could try:

SELECT *
FROM office
ORDER BY (hour/job) ASC
LIMIT 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download