Jump to content

Couple Questions, query related.


nickn

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.