Welcome to WebmasterWorld Guest from 54.144.124.152

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

creating a new temp column in mysql with some math

     

whatson

1:04 am on Nov 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

9:49 am on Nov 10, 2012 (gmt 0)

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



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...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month