mysql - Calculating average from 2 database table colums -


i trying calculate average based on values 2 table columns in mysql.

lets have table structure:

id | user_id | first_score | last_score 1  | 1       |  10         | 60 2  | 1       |  70         | 10 3  | 1       |  100        | null 

what trying achieve here, calculating avg of highest value (i.e. 60, 70, 100). seeing in different colums, not sure how go it..

you solve greatest function. unfortunately results in null when 1 or both values null. so:

select avg( greatest( coalesce(first_score,last_score) , coalesce(last_score,first_score) ) ) mytable; 

Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -