Sort table by an attribute that is not in the SQL Query

Asked

Viewed 183 times

1

I have the following query in my PHP code:

SELECT id, totaldias, totalferiados FROM dias WHERE MONTH(data) = '$mes' ORDER BY totaldias

So far, so good. But I implemented in the system a percentage that works as follows: In another query I take the person’s date of entry into the company, and count how many days she has worked since entering, and I shoot the percentage of how many days she was on duty and play on the table. But how to order from who took more duty to what you took less? But the calculation is done outside the query, how do I get order?

  • Make this calculation within your query.

  • "Play on the table"? If the dice is on the table, just sort by it.

  • In the table I mentioned was the php table. Sorry. I will try to do the calculation inside the query itself.

  • 1

    If you calculate % with PHP, use it to sort. Enter the code you are using

  • Without seeing the rest of your code it is difficult to help, but you could do everything as a single query, including calculating the percentage and using a ORDER BY to sort. Post the other query and the percentage calculation to help you better.

  • Later I will post, is that stayed at work. But I will post more.

  • Did you find a solution? Poste as an answer to help other people.

  • The project I was working on was canceled and I haven’t tested the solution anymore.

Show 3 more comments
No answers

Browser other questions tagged

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