Jump to content

[SOLVED] Complex query, for me at least...


jcbarr

Recommended Posts

Okay here is the query that I have right now

[code]SELECT team, SUM(ch+ph+sp) as bvalue, SUM(`as`+co+pavg) as pvalue FROM rosters GROUP BY team ORDER BY bvalue+pvalue[/code]

So here is the question, and I'm not sure if I can do this or not.

I only want to select the SUM(ch+ph+sp) where pos<>P and I only want to select SUM(`as`+co+pavg) from where pos=P. I want to GROUP BY team and order by the value of bvalue+pvalue...

So can I do this? The above query isn't working for me when trying to use it with mysql_fetch_assoc I am told that it is not a valid argument.

So, does anyone know how to do this? Can I do it in one query?
Link to comment
Share on other sites

Hmm.. you could use this trick:

[code=php:0]SELECT team, SUM(IF(pos<>P,ch+ph+sp,0)) as bvalue, SUM(IF(pos=P,`as`+co+pavg,0)) as pvalue FROM rosters GROUP BY team ORDER BY bvalue+pvalue[/code]

My syntax may not be 100% correct but the idea is sound.  Otherwise you can just use 2 queries, if the overhead isn't a large factor.
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.