RE: divide-column?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Murray @ PlanetThoughtful wrote:
> >>Hi there!
> >>
> >>How do I do a sort in PHP where a column in a db must be two other
> columns
> >>divided...`?
> >
> >
> > <snip>
> >
> > Hi Gustav,
> >
> > You should be able to use the divide operation in your query's ORDER BY
> > clause.
> >
> > Eg
> >
> > SELECT * FROM mytable ORDER BY (field1 / field2)
> 
> You might need to do:
> 
> SELECT *, (field1 / field2) AS divField FROM mytable ORDER BY divField
> 
> as I'm not sure if you can use expressions like that in the ORDER BY
> clause. Maybe...

Hi Jasper,

The statement I included worked in testing when run against my local
installation of MySQL.

Still, good to point out different options, in the event that something goes
awry.

Regards,

Murray
---
"Lost in thought..."
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux