MySQL 查询选择和计算值
SELECT
if('1000'>plan_limit_max,'1000'-plan_limit_max,0) as 'Overage',
if(`per_hour_cost`='0', `per_period_cost`+'10'*`Overage`, per_hour_cost*720) AS 'Total'
FROM `service_price`
order by Total asc
;
第 3 行出现 Overage
错误 有
Error Code: 1054. Unknown column 'Overage' in 'field list'
没有办法通过一个查询来完成我想要的操作? 我想按总价对结果进行排序,但要计算它,我必须计算超出限制的使用情况。
我知道应该有其他方法可以做到这一点,使用多个查询,创建视图等。 我只是想知道是否有更简单的查询。
SELECT
if('1000'>plan_limit_max,'1000'-plan_limit_max,0) as 'Overage',
if(`per_hour_cost`='0', `per_period_cost`+'10'*`Overage`, per_hour_cost*720) AS 'Total'
FROM `service_price`
order by Total asc
;
There is an error with Overage
at line 3
Error Code: 1054. Unknown column 'Overage' in 'field list'
Is there a way to do what I want with one query?
I want to order results by total price, but to calculate it I have to calculate the usage exceeds the limit.
I know there should be other ways to do it, use more than one queries, create views, etc..
I just wonder if there is a simpler query for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在子查询中计算一次
Overage
:You can compute
Overage
once, in a subquery:Overage 未定义为查询的一部分,仅定义为结果中的列标题。您无法引用该列,因为它还不存在...您必须使用类似于下面的 SQL 的内容:
Overage is not defined as part of the query, only as the column header in the result. You cannot reference that column as it does not yet exist... You've got to use something like the SQL below:
您在 OVERAGE 中输入“``”时出错。您必须在 OVERAGE 中使用“”。
You have an error putting " `` " in OVERAGE. You must use ' ' in OVERAGE.