【发布时间】:2019-11-29 16:31:24
【问题描述】:
我在 mysql 中为基于客户的结果集开发解决方案时遇到了一些麻烦。想象一下,我有一些主数据和一些客户特定的(财务)变量。我想为数据创建一个视图,其中包含特定于客户变量的计算列。
例如:带有价格的主数据产品,带有个人折扣、利率和财务运行时间等财务输入参数的客户表。我通过创建存储过程创建了具有递归 cte 的客户特定财务计划。
现在我想要一个产品结果集,其中有一列指定价格和客户数据(复杂计算,包括平均利率和运行时间)。我想创建一个 Select 结果集,我可以在查询中将其用作网站或分析的结果集。
问题: -mysql 存储的函数不返回表 -> 没有函数 -mysql 存储过程不能嵌入到视图中 -> 过程不能被进一步过滤(Select * from (call procedure) where "more filters") -mysql 视图不能包含参数或变量(输入当前查看的客户)
解决方案可能是什么样的?我没有更多的想法了。感谢您的帮助。
Set @interestrate = (select ... where customer = @INPUT)
Set @runtime = (select ... where customer = @INPUT)
Select
productid,
price,
(
price * avg(recursive cte @interestrate, @runtime) * @runtime
) as calculation
from masterdata
where
criterium_a = "abc"
criterium_b = "def"
【问题讨论】:
标签: mysql sql stored-procedures parameters stored-functions