how to Sort calculated columns using server-side processing

how to Sort calculated columns using server-side processing

manuelescalonamanuelescalona Posts: 2Questions: 1Answers: 0

I built a server-side processing table with few calculated columns based on some values returned by a SQL, for example

ad_rev = ($row['page_views'] * $rpm)/1000;
total_rev = $ad_rev + $row['commission'];
$rpm = a factor taken from another table using a separate query.

How to add any calculated column into the "ORDER BY"?

SELECT content, page_views, commission, clicks FROM table WHERE date >= ? AND date <= ? ORDER BY...

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    You can't since the calculation is being done in PHP rather than SQL. So by the time the calculation is done, the SQL data has already been sorted, filtered and read.

    Best option for this sort of thing is to use an SQL VIEW to do that calculation and then post your server-side processing script at that VIEW to read the data.

    Allan

  • manuelescalonamanuelescalona Posts: 2Questions: 1Answers: 0

    Hi Allan, will follow your suggestion.

    Thanks,
    Manuel

This discussion has been closed.