在MySQL中创建视图时,如何将某一列定义为使用同一视图中的其他列计算的结果?
假设我们有一个名为 Prices
的表,其中包含 Price1
和 Price2
列,我想创建一个名为 Totals
的视图code> ,其中一个名为 PriceTotals
的列在表格上添加 Price1
和 Price2
,以及第二个名为 PriceCut
的列这只是简单地划分2 视图中的 PriceTotals
:
create view `Totals` as
select
`Price1` + `Price2` as `PriceTotals`,
/**Put column definition here that divides PriceTotals by 2**/ as `PriceCut`
from `Prices`;
我该如何处理?
So let's say we have a table called Prices
with columns Price1
and Price2
, and I want to create a View called Totals
with a column called PriceTotals
that adds Price1
and Price2
on the table, and a second column called PriceCut
that simply divides PriceTotals
on the view by 2:
create view `Totals` as
select
`Price1` + `Price2` as `PriceTotals`,
/**Put column definition here that divides PriceTotals by 2**/ as `PriceCut`
from `Prices`;
How do I go about that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你就不能这样做吗?
Can't you just do this?