MySQL 选择查询,从即时生成的列中选择位置
我有一个(我的)SQL 问题。如果我有一张表,假设名为 Cars,具有各种列,其中两个是 INT,我想将其加在一起,一个称为后轮,另一个称为前轮。
时,我可以执行此查询将它们添加在一起
当我选择select (backwheels+frontwheels) as Totalwheels from Cars;
;效果很好,但是当我尝试在 Totalwheels 列上进行选择时,我得到错误
从汽车中选择(后轮+前轮)作为totalwheels,其中totalwheels = 4;
我得到的错误:
“where”中的未知列“totalwheels” 条款'
是否可以以某种方式从实际上不存在的列中进行选择?
I have a (my)SQL question. If I have a table, let's say called Cars with various columns, two of which are INT which I want to add together, one called backwheels and the other called frontwheels.
I can do this query to add them together when I select
select (backwheels+frontwheels) as totalwheels from Cars;
which works fine, but when I try and do a select where on that totalwheels column, I get an error
select (backwheels+frontwheels) as totalwheels from Cars where totalwheels=4;
the error I get back:
Unknown column 'totalwheels' in 'where
clause'
Is it possible to somehow select from a column which doesn't really exist like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用:
或:
You can use:
OR:
导致此错误的原因是您的表没有“totalwheels”列,并且您的 where 子句尝试在不存在的列上运行条件。
您可以尝试使用 -
This error is caused because your table doesn't have a column "totalwheels" and your where clause is trying to run a condition on a column that doesn't exist.
You can try using -
最好尝试使用 Alias:
Better try with Alias: