解决方案 您需要使用子查询.SELECT c.d AS a, c.d + 2 AS b发件人(SELECT 1+1 AS d) c结果||乙 |---------|2 |4 |I have a query in Sqlite that involves a complicated column calculation, let's say:SELECT 1+1 AS a;I want to have this calculation selected as a, but I also need to use it as a component of another calculation:SELECT 1+1 AS a, a+2 AS b;Unfortunately this produces the error:Error: no such column: aI know that I could simply repeat the calculation again for b:SELECT 1+1 AS a, 1+1+2 AS b;But assuming 1+1 is some complicated and expensive operation, is there any way that I can reference it later in the SELECT without having to recalculate it? 解决方案 You need to use a sub-query.SELECT c.d AS a, c.d + 2 AS bFROM (SELECT 1+1 AS d) cResult| a | b |---------| 2 | 4 | 这篇关于如何通过另一个计算列使用计算列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 03:50