homepage Welcome to WebmasterWorld Guest from 54.147.248.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
creating a new temp column in mysql with some math
whatson

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4517671 posted 1:04 am on Nov 10, 2012 (gmt 0)

Ok, I have some numeric columns, and I want to establish and average for them.
e.g.
col 1 value = 4
col 2 value = 7
col 3 value = 3
col 4 value = 9
I want to be able to create (4+7+3+9)/4, as another column in a query. Then I want to use this number as for ORDER BY for another table.
With the numbers table there is another column that has an id relating to this other table.
I really can't get my head around this. It's hard enough to explain. Let me know if you need more help in explaining.

 

vincevincevince

WebmasterWorld Senior Member vincevincevince us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4517671 posted 9:49 am on Nov 10, 2012 (gmt 0)

1)
alter table X add column average_float float(6,2) <- or simlar
2)
update X set average_float = (col1+col2+col3+col4)/4;
3)
in your Y table which references X:
select * from Y (.....) order by (select average_float from X where X.id = Y.id) desc

or similar...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved