Jump to content


Photo

Couple Questions, query related.


  • Please log in to reply
1 reply to this topic

#1 nickn

nickn
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 17 November 2003 - 04:38 PM

Here is the basic fields of a table.

field 1, field 2, field 3. Field 1 is varchar, 2 and 2 are int.

Select field1, sum(field2), sum(field3) GROUP BY field1 ORDER BY ??? sum(field2)???

I am trying to put the returned results in order from the sum of field 2

ie...

field1 field 2 field3
nick 20 2
matt 10 4
jason 5 1


Another Question. Can I order by 2 sums that have been divided.


ie...

SELECT field1, sum(field2), sum(field3) FROM TABLE GROUP BY field1 ORDER BY (field2 / field3) DESC


Again with the sum of 2 fields, then divided to get an avg between the 2 sums and ordered correctly by the avg.

ie...

field 1 field2 field3 AVG
nick 20 5 4
matt 15 5 3
jason 10 5 2

#2 sirmanson

sirmanson
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationTucson, AZ USA

Posted 18 November 2003 - 03:26 PM

You can order by any formula you wish

Either of these will work :

select col1, col2/col3from tableorder by col1/col2
or

select col1, col2/col3from tableorder by col2/col3





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users