SQL Query

payjo

Senior member
Sep 6, 2001
267
0
0
I have a baseball table that contains the fields: atbats, runs, rbis, singles, doubles, triples

I want to run a query that is sorted by batting avg [(singles+doubles+triples+hrs)/atbats]. Is there a way to create a variable within the query and then sort it by that variable.

I'm using mySQL as the db server and Coldfusion to spit out the data.

Thanks in advance.
 

Shazam

Golden Member
Dec 15, 1999
1,136
1
0
You should be able to do something like:

select (singles+doubles+triples+hrs)/atbats as battingAvg
from tablename
order by (singles+doubles+triples+hrs)/atbats
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: Shazam
You should be able to do something like:

select (singles+doubles+triples+hrs)/atbats as battingAvg
from tablename
order by (singles+doubles+triples+hrs)/atbats

You defined battingAvg, why not use it?

select (singles+doubles+triples+hrs)/atbats as battingAvg
from tablename
order by battingAvg