Draw Yang Hui triangle using SQL

Source: Internet
Author: User
It is interesting to see a post on csdn about the SQL expression for drawing the Yang Hui triangle. Later, I thought about how to calculate C (n, m) n based on the combined number of Yang Hui triangle without using a temporary table! [M! (N-m)!], . The following is the complete SQL code: usetempdb, and the calculation method based on the combined number of Yang Hui triangles: C (n, m) n! [M! (N-m )!

It is interesting to see a post on csdn about the SQL expression for drawing the Yang Hui triangle. Later, I thought about how to calculate C (n, m) = n according to the combination number calculation method of the Yang Hui triangle without using a temporary table! /[M! (N-m)!], . The following is the complete SQL code: use tempdb, according to the Yang Hui triangle combination number calculation method: C (n, m) = n! /[M! (N-m )!

I accidentally saw a post on csdn about the SQL expression, website space, Hong Kong server, and Hong Kong Space for drawing the Yang Hui triangle. Later, I thought about how to calculate C (n, m) = n according to the combination number calculation method of the Yang Hui triangle without using a temporary table! /[M! (N-m)!], .

The complete SQL code is as follows:

Use tempdb, according to the combination number calculation method of Yang Hui triangle: C (n, m) = n! /[M! (N-m)!] For drawing, see; with cte_n as (), cte_1 as (select n. r, B. data_lsefrom cte_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. r <= isnull (nullif (n. r-m.r, 0), 1) for xml path (''), 1, 1,'') as v) F3 (), 0), @ cols) ascfor xml path (''), 1, 1,'') as data_lse) bwhere n. r <= @ rows) (, '') + data_lse from cte_1exec (@ SQL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.