是否有方法在同一查询中引用MySQL查询的部分?
例如:
SELECT 50000 AS starting_principle, .065*50000 AS interest,
principle + interest AS principle_plus_interest查询集中的第三列principle_plus_interest给出了一个错误。除了编写50000 + .065*50000 AS principle_plus_interest之外,还有什么方法可以对此进行编码吗?
发布于 2015-06-10 22:19:12
您不能引用select列表(或where子句)中的别名。解决这一问题的一种方法是使用子查询:
SELECT starting_principle,
interest,
principle + interest AS principle_plus_interest
FROM (SELECT 50000 AS starting_principle, .065*50000 AS interest
FROM some_table) thttps://stackoverflow.com/questions/30768250
复制相似问题