在 SELECT 中重用别名
我想做的是添加另一列来计算 (cr - dr)
鉴于您无法在 SELECT 子句中重复使用别名,您将如何计算 total
SELECT SUM(b.bet_win * cy.fx_rate )as dr, SUM(b.bet_loss * cy.fx_rate ) as cr, cr+dr as total
FROM ....
WHERE ....
What I am trying to do is add another column that calculates (cr - dr)
Seeing as you cannot re-use an alias inside a SELECT clause, how would you go about calculatin total
SELECT SUM(b.bet_win * cy.fx_rate )as dr, SUM(b.bet_loss * cy.fx_rate ) as cr, cr+dr as total
FROM ....
WHERE ....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 SQL Server 或 Oracle 中,我会使用 CTE,但由于您使用的是 MySQL,因此您会使用子查询:
In SQL Server or Oracle, I'd use a CTE, but since you're using MySQL, you'd use a subquery:
编辑:不起作用。见评论。
在这种情况下,使用用户变量更快?
EDIT: DOES NOT WORK. See comments.
Isn't using a user variable faster in this case?
您可以在“总计”栏中重复计算。
You can repeat the calculations in the "total" column.