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: 50,248Questions: 1Answers: 7,465 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

Sign In or Register to comment.