Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Order by math

I want to order a result by fieldx * fieldy, for example:

Row 1: fieldx = 10 fieldy = 10 Total: 100

Row 2: fieldx = 11 fieldy = 5 Total: 55

Row 1 has to appear first. Couldn't find anything about it. It's for a codeIgniter project, so if there is a solution with that I'm very happy.

Thanks!

like image 723
Kees Avatar asked Nov 01 '09 18:11

Kees


1 Answers

It's okay to do math in the order by clause:

 select *
 from YourTable
 order by fieldx * fieldy
like image 166
Andomar Avatar answered Sep 22 '22 22:09

Andomar