我在解释我的必要性时遇到了麻烦,因此我将介绍这种情况。
我们想要创建一个报告,其中已经完成了这些计算,并且根据此场景的值,我们认为第一步将是返回以下内容:
圆量(KG)
1 125
2 125
3 125
4 125
5 125
6 125
7 125
8 125
9 27,5
之后,可以通过简单的操作重新计算组件。
问题在于,我们无法想到一种获得期望回报的方法,也无法想到达成上述报告的另一种方法。
我们所能做的就是得到除法的整数部分
SELECT FLOOR(1027.5/125) AS "TEST" FROM DUMMY
其余的
SELECT MOD(1027.5,125) AS "TEST" FROM DUMMY
我们正在使用:
任何帮助,将不胜感激
提前致谢!
有几种方法可以实现您想要的描述。
一种方法是将需求转换为采用两个输入参数值并返回生产回合表的函数。
看起来可能像这样:
create or replace function production_rounds(
IN max_production_volume_per_round decimal (10, 2)
, IN production_order_volume decimal (10, 2)
)
returns table (
production_round integer
, production_volume decimal (10, 2))
as
begin
declare rounds_to_produce integer;
declare remainder_production_volume decimal (10, 2);
rounds_to_produce := floor( :production_order_volume / :max_production_volume_per_round);
remainder_production_volume := mod(:production_order_volume, :max_production_volume_per_round);
return
select /* generate rows for all "max" rounds */
s.element_number as production_round
, :max_production_volume_per_round as production_volume
from
series_generate_integer
(1, 1, :rounds_to_produce + 1) s
UNION ALL
select /* generate a row for the final row with the remainder */
:rounds_to_produce + 1 as production_round
, :remainder_production_volume as production_volume
from
dummy
where
:remainder_production_volume > 0.0;
end;
您可以像使用任何表一样使用此函数-但可以使用参数:
select * from production_rounds (125 , 1027.5) ;
PRODUCTION_ROUND PRODUCTION_VOLUME
1 125
2 125
3 125
4 125
5 125
6 125
7 125
8 125
9 27.5
可能需要解释的位是SERIES_GENERATE_INTEGER
。这是HANA特定的内置函数,可从“系列”返回许多记录。这里的序列是最小和最大限制内的一系列周期,在两个邻接周期之间具有一定的步长。有关如何工作的更多信息,请参见HANA参考文档,但是现在,这只是用X行生成结果集的最快方法。
此系列生成器用于创建所有“完整”生产回合。UNION ALL
然后,对于第二部分,通过从内置表DUMMY
(DUAL
在Oracle中)中进行选择来创建仅一行,该表保证只有一条记录。最后,如果实际上没有剩余部分,则需要“禁用”第二部分,这是通过该WHERE
子句完成的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句