我有一个SQL问题。如果我有一个表,比如说有不同列的汽车,其中两个是INT,我想加在一起,一个叫后轮,另一个叫前轮。
当我选择
select (backwheels+frontwheels) as totalwheels from Cars;
这很好,但是当我尝试在totalwheels列上选择一个位置时,我得到一个错误
select (backwheels+frontwheels) as totalwheels from Cars where totalwheels=4;
我返回的错误是:
“where”中的未知列“totalwheels”
条款'
是否有可能从一个不真正存在的专栏中选择?

最佳答案

您可以使用:

select (backwheels+frontwheels) as totalwheels from Cars
where (backwheels+frontwheels)=4;

或:
SELECT * from
(select c.*, (backwheels+frontwheels) as totalwheels from Cars)
where totalwheels=4;

10-04 10:42