Sort by value outside the Mysql query

Asked

Viewed 46 times

0

I need to sort the result of my search by a value that is outside the query.

For example, in the query I have a field called answer and with this value I make a calculation. But the result of that calculation is not in table.

My query

$search = mysql_query('SELECT * FROM simuladosrespondidos AS sr 
            JOIN usuarios AS u ON u.idUsuarios = '.$idUsuario.' AND sr.idUsuarios = u.idUsuarios 
            JOIN questoes AS q ON q.idQuestao = sr.idQuestao WHERE sr.idSimulado = '.$idSimulado.'');

What I do is I take the value of a column called answers and do the calculation on top of it. How to order by that calculation?

Note: The calculation q do actually is the following: I get the value of the answer column. Each user has several answers. If it equals 'C' we are + 1 in a variable here. If it equals 'E' I decrease - 1 and if it equals E I do nothing and at the end of everything I have a value and it is for that value I want to order.

  • Post as your query. Examples of values to make it easier to view your need.

  • You are doing your calculation in mysql or php?

  • I edited with my query

  • Edit again with the result after you do the calculation.

  • I edited the question, guys

  • Passes more information, if somehow you are saving an array with the calculation of information, right or wrong and final value. You can sort this array with PHP.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.