Home >Database >Mysql Tutorial > 通过SQL绘制杨辉三角

通过SQL绘制杨辉三角

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:44:051438browse

无意中在csdn上看到一帖有关绘制杨辉三角的sql表达式,感觉很有意思。后来自己想下不借助临时表,根据杨辉三角的组合数计算方法C(n,m)=n!/[m!(n-m)!],进行绘制。 以下是完整的SQL代码: use tempdb , ,, 根据杨辉三角的组合数计算方法:C(n,m)=n!/[m!(n-m)!

无意中在csdn上看到一帖有关绘制杨辉三角的sql表达式,网站空间,香港服务器,香港空间,感觉很有意思。后来自己想下不借助临时表,根据杨辉三角的组合数计算方法C(n,m)=n!/[m!(n-m)!],进行绘制。

以下是完整的SQL代码:

use tempdb , ,, 根据杨辉三角的组合数计算方法:C(n,m)=n!/[m!(n-m)!]进行绘制 参照: ;with cte_n as ( ) ,cte_1 as(select n.r,b.data_lse from cte_n n (((F1.vF2.vF3.v,(),0),@cols)) from cte_n m (i.r) ,0)),1) for xml path('')),1,1,'') as v ) F1 (i.r) ,0)),1) for xml path('')),1,1,'') as v ) F2 (i.r) from cte_n i where i.risnull((nullif(n.r-m.r,0)),1) for xml path('')),1,1,'') as v ) F3 (),0),@cols) asc for xml path('') ),1,1,'') as data_lse )b where n.r @rows ) (,'')+data_lse from cte_1 exec(@sql)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn