» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2006, 05:09 PM
blewett blewett is offline
Junior Member
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
blewett is on a distinguished road
Default AVG and SUM query

hi folks
can't work that out

is there anything wrong with this code

Code:

SELECT id FROM tb_empire
WHERE (networth > AVG(networth));

if yes, point that out
thanks in advance -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-03-2006, 05:10 PM
desilva desilva is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
desilva is on a distinguished road
Default

You aren't defining how the group should be performed.

You are using a GROUP function like AVG() in the WHERE clause and you can't do this since the values in the WHERE clause has to be known in the beginning of processing the table.
-- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 08-03-2006, 05:13 PM
sylvestor sylvestor is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
sylvestor is on a distinguished road
Default

Hey, this will do the job for you


select id
from tb_empire
where networth
> ( select avg(networth)
from tb_empire)



Glad to help you -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #4  
Old 08-03-2006, 05:15 PM
foghorn foghorn is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
foghorn is on a distinguished road
Default

Hi dude

Yes, upgrade your version of mysql and also read the sticky thread at the top of this forum telling you about your outdated version of mysql.

Regards
foghorn -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #5  
Old 08-03-2006, 05:17 PM
adam adam is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
adam is on a distinguished road
Default

It is always a good idea to post the actual error message.

Code:
select e1.networth
from tb_empire e1, tb_empire e2
group by e1.networth
having e1.networth > avg(e2.networth) -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:07 AM.