如何在SQL Server 2012中评估k!
之类的数学表达式?
答案 0 :(得分:1)
我真的认为在SQL Server中计算阶乘是一个坏主意,但是如果您必须这样做
with pair (n, f) as (
select 0 as n, 1 as f
union all
select p.n + 1 as n, p.f * (p.n + 1) from pair p
where p.n < 5 -- factorial of 5
)
select f from pair where n = 5; -- factorial of 5
您需要将N
的值放置两次。结果:
f
---
120
答案 1 :(得分:0)
尝试一下:
G.edges(5, data=True)
> EdgeDataView([(5, 2, {'weight': 4}), (5, 6, {'weight': 2}), (5, 3, {'weight': 14}), (5, 4, {'weight': 10})])