我需要基于此执行计算:
(col1 + col2 + col3 + col4 + col5) /col6
完成此计算后,我想根据获得的结果执行 orderby。
请建议。我知道如何执行这样的求和:
SELECT SUM(column1) + SUM(column2) + SUM(columnN) FROM mytable
我需要基于此执行计算:
(col1 + col2 + col3 + col4 + col5) /col6
完成此计算后,我想根据获得的结果执行 orderby。
请建议。我知道如何执行这样的求和:
SELECT SUM(column1) + SUM(column2) + SUM(columnN) FROM mytable
SELECT (column1+column2+columnN)/column6
FROM mytable
ORDER BY (column1+column2+columnN)/column6
我想你的意思是:
SELECT ((column1 + column2 + columnN) / column6) as calc
FROM mytable order by calc
SELECT (col1 + col2 + col3 + col4 + col5) /col6 as calculated
FROM your_table
ORDER BY calculated
试试这个 ::
SELECT (column1+column2+columnN) as total,
total/column6 as average
FROM mytable
ORDER BY total