楼主: newkid

首届NoCOUG国际SQL挑战赛

[复制链接]
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
11#
发表于 2009-9-15 12:37 | 只看该作者
原帖由 newkid 于 2009-9-15 09:09 发表
要拼效率的话就得有扎实的数学功底,那个意大利人Alberto Dell'Era连傅里叶变换都用上了。

快速傅立叶变换 http://class.htu.cn/SZBJ/6/6_10.htm实在是看不懂啊

[ 本帖最后由 〇〇 于 2009-9-15 12:45 编辑 ]

__class.htu.cn_SZBJ_6_6_10.pdf

103.17 KB, 下载次数: 16

__class.htu.cn_SZBJ_6_6_40.pdf

97.88 KB, 下载次数: 11

__class.htu.cn_SZBJ_6_6_20.pdf

103.4 KB, 下载次数: 10

__class.htu.cn_SZBJ_6_6_30.pdf

88.8 KB, 下载次数: 11

使用道具 举报

回复
论坛徽章:
69
生肖徽章2007版:羊
日期:2008-11-14 14:42:19复活蛋
日期:2011-08-06 08:59:05ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20版主4段
日期:2012-05-15 15:24:11
12#
发表于 2009-9-15 14:56 | 只看该作者
啥時候Newkid也來一個挑戰賽 ?

牛啊.

使用道具 举报

回复
论坛徽章:
67
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-01-04 11:49:54ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2011-11-01 08:02:09现任管理团队成员
日期:2011-05-07 01:45:082011新春纪念徽章
日期:2011-02-18 11:42:472011新春纪念徽章
日期:2011-01-25 15:42:56
13#
发表于 2009-9-15 18:48 | 只看该作者
原帖由 〇〇 于 2009-9-15 09:26 发表
意大利人已经夺冠,
作者也公布了他的解法
http://iggyfernandez.wordpress.com/2009/08/09/the-tenth-solution/

cant.JPG (88.71 KB, 下载次数: 12)

cant.JPG

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
14#
发表于 2009-9-15 19:07 | 只看该作者

回复 #13 sir.liang 的帖子

防火墙的功劳,用google快照看

使用道具 举报

回复
论坛徽章:
67
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-01-04 11:49:54ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2011-11-01 08:02:09现任管理团队成员
日期:2011-05-07 01:45:082011新春纪念徽章
日期:2011-02-18 11:42:472011新春纪念徽章
日期:2011-01-25 15:42:56
15#
发表于 2009-9-15 20:28 | 只看该作者
原帖由 〇〇 于 2009-9-15 19:07 发表
防火墙的功劳,用google快照看


好!

使用道具 举报

回复
论坛徽章:
55
马上加薪
日期:2014-02-19 11:55:142010广州亚运会纪念徽章:排球
日期:2011-04-27 13:27:19SQL大赛参与纪念
日期:2011-04-13 12:08:172011新春纪念徽章
日期:2011-02-18 11:43:332011新春纪念徽章
日期:2011-01-25 15:42:562011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:41:502011新春纪念徽章
日期:2011-01-25 15:41:01生肖徽章2007版:兔
日期:2011-01-20 12:58:49
16#
发表于 2009-9-15 20:56 | 只看该作者
学习

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
17#
 楼主| 发表于 2009-9-15 21:30 | 只看该作者
昨天不是还能看吗?都是这国庆闹的。The Tenth SolutionAugust 9, 2009 Iggy Fernandez Leave a comment Go to comments



0


0

Rate This




I got the idea for the First International NoCOUG SQL Challenge from a trick question that I was asked at a job interview several years ago: “How would you calculate the probabilities of obtaining various sums in two throws of a [six-sided fair] die?” No, this was not at Google—I’ve never got past the front door there—but I’ve heard that Google too likes to stress candidates by asking questions that are completely unrelated to the job they will be doing; for example, How would you sell ice to an Eskimo? I’d prefer to be honest when asked such questions and say—with an engaging smile, of course—“I’d like to pass on the question because it has nothing to do with the job that I’ll be doing” but I know that you’re supposed to play along with such tomfoolery if you really want the job.
I flubbed the trick question but the answer came to me on the drive home; it always does. One simply has to enumerate each possibility—for example, two sixes—and compute the probability of each possibility. Since the die has six faces and since the die is thrown twice, there are 36 possibilities. Since the die is fair and since the two throws are independent of each other, each possibility has the exact same probability; that is, 1/6 * 1/6 which equals 1/36. However, some possibilities give rise to the same sum—for example, 3 + 4 equals 4 + 3—and we have to add up their probabilities. Here is the exhaustive enumeration of possibilities.
First throwSecond ThrowSumProbability
1121/36
1231/36
1341/36
1451/36
1561/36
1671/36
2131/36
2241/36
2351/36
2461/36
2571/36
2681/36
3141/36
3251/36
3361/36
3471/36
3581/36
3691/36
4151/36
4261/36
4371/36
4481/36
4591/36
46101/36
5161/36
5271/36
5381/36
5491/36
55101/36
56111/36
6171/36
6281/36
6391/36
64101/36
65111/36
66121/36
Upon grouping by the sum of the faces, we arrive at the final answer.
SumTotal Probability
21 * 1/36
32 * 1/36
43 * 1/36
54 * 1/36
65 * 1/36
76 * 1/36
85 * 1/36
94 * 1/36
103 * 1/36
112 * 1/36
121 * 1/36
I then got even cleverer—as inevitably happens to me on the drive home from an unsatisfactory interview. I realized that I could solve the problem with a clever little SQL statement. Assume that the following data is stored in a table called Die.
Face_valueProbability
11/36
21/36
31/36
41/36
51/36
61/36
The following SQL statement can then be used to process the data and compute the required probabilities.
view plaincopy to clipboardprint?

  • SELECT
  •   face_value,   

  • SUM (probability) AS probability   

  • FROM
  • (   

  • SELECT
  •     d1.face_value + d2.face_value AS face_value,   
  •     d1.probability * d2.probability AS probability   

  • FROM die d1 CROSS
    JOIN die d2   
  • )   

  • GROUP
    BY face_value;  

SELECT  face_value,  SUM (probability) AS probabilityFROM(  SELECT    d1.face_value + d2.face_value AS face_value,    d1.probability * d2.probability AS probability  FROM die d1 CROSS JOIN die d2)GROUP BY face_value;Isn’t that clever? But what if the die was not fair? What if the die had more than six faces? It wouldn’t matter; my clever query would still work. I mentally patted myself on the back even though I knew in my heart that my chance had passed and I would not get the job. Lady Luck knocks only once, after that she sends her daughter, Miss Fortune.
While waiting for the telephone call that never came, I toyed with the problem of computing the probabilities of obtaining various sums in more than two throws. That was simple enough, it just required more joins. For example, here’s what to do in the case of three throws.
view plaincopy to clipboardprint?

  • SELECT
  •   face_value,   

  • SUM (probability) AS probability   

  • FROM
  • (   

  • SELECT
  •     d1.face_value + d2.face_value + d3.face_value AS face_value,   
  •     d1.probability * d2.probability * d3.probability AS probability   

  • FROM die d1 CROSS
    JOIN die d2 CROSS
    JOIN die d3   
  • )   

  • GROUP
    BY face_value;  

SELECT  face_value,  SUM (probability) AS probabilityFROM(  SELECT    d1.face_value + d2.face_value + d3.face_value AS face_value,    d1.probability * d2.probability * d3.probability AS probability  FROM die d1 CROSS JOIN die d2 CROSS JOIN die d3)GROUP BY face_value;But what if the number of throws was not specified in advance? What if it was an input to the program? That was more difficult but I finally found a way. I cooked up a silly story about the Wizard of “Odds” at the School of “Hogwash” (Hogwarts) having discovered an ancient jade icosahedron in the magic chamber of mystery and published the puzzle in the November 2007 issue of the NoCOUG Journal. There were no entries but at least one person mentioned to me that he had spent a couple of hours trying to find a solution.
A year and a half passed and I proposed to the board of the Northern California Oracle Users Group (NoCOUG) that we hold an international SQL competition. I got Apress to offer some prizes; they are always very supportive of user groups such as NoCOUG. The results of the competition were spectacular; there were nine radically different entries from seven countries and three continents.
Here is my own solution to the problem. It is a variant of André Araujo’s solution; it is equally fast but has no logical limitations. However, it does have a hidden physical limitation which I will discuss later.
Even though my solution is quite fast, it would not have pleased the judges because it depended on a trick that does not work in any database except Oracle. I dynamically generate an SQL statement and execute it using the DBMS_XMLGEN.getxmltype function; I then use the XMLTABLE function to display the results.
As is the case with André Araujo’s solution, my solution does not require as many joins as there are throws; that is, using binary arithmetic and frequent grouping, one can drastically reduce the number of joins.
Here is the SQL statement that I generate for seven throws of the die. I use a sequence of common table expressions. Here, first, are the probabilities for one throw of the die.
view plaincopy to clipboardprint?

  • l0 AS
  • (   

  • SELECT face_value AS f, probability AS p   

  • FROM die   
  • )  

l0 AS(  SELECT face_value AS f, probability AS p  FROM die)The probabilities for two throws of the die are computed by joining the previous expression with itself.
view plaincopy to clipboardprint?

  • l1 AS
  • (   

  • SELECT f, SUM (p) AS p   

  • FROM
  •   (   

  • SELECT t1.f + t2.f AS f, t1.p * t2.p AS p   

  • FROM l0 t1, l0 t2   
  •   )   

  • GROUP
    BY f   
  • )  

l1 AS(  SELECT f, SUM (p) AS p  FROM  (    SELECT t1.f + t2.f AS f, t1.p * t2.p AS p    FROM l0 t1, l0 t2  )  GROUP BY f)The probabilities for four throws of the die are likewise obtained by joining the previous expression with itself.
view plaincopy to clipboardprint?

  • l2 AS
  • (   

  • SELECT f, SUM (p) AS p   

  • FROM
  •      (   

  • SELECT t1.f + t2.f AS f, t1.p * t2.p AS p   

  • FROM l1 t1, l1 t2   
  •      )   

  • GROUP
    BY f   
  • )  

l2 AS(  SELECT f, SUM (p) AS p   FROM     (       SELECT t1.f + t2.f AS f, t1.p * t2.p AS p       FROM l1 t1, l1 t2     )   GROUP BY f)The probabilities for seven throws of the die can be obtained by joining all three of the above expressions because 7 = 4 + 2 + 1. There is a join with the Dual table in the very center of the query; this is the same trick that is used to great effect by André Araujo.
view plaincopy to clipboardprint?

  • SELECT f, SUM (p) AS p   

  • FROM
  •   (   

  • SELECT t1.f + t2.f AS f, t1.p * t2.p AS p   

  • FROM
  •       l2 t1,   
  •       (   

  • SELECT f, SUM (p) AS p   

  • FROM
  •           (   

  • SELECT t1.f + t2.f AS f, t1.p * t2.p AS p   

  • FROM
  •               l1 t1,   
  •               (   

  • SELECT f, SUM (p) AS p   

  • FROM
  •                 (   

  • SELECT t1.f + t2.f AS f, t1.p * t2.p AS p   

  • FROM
  •                     l0 t1,   
  •                     (   
  •                       (   

  • SELECT 0 AS f, 1 AS p   

  • FROM DUAL   
  •                       )   
  •                     ) t2   
  •                 )   

  • GROUP
    BY f   
  •             ) t2   
  •           )   

  • GROUP
    BY f   
  •       ) t2   
  •   )   

  • GROUP
    BY f  

SELECT f, SUM (p) AS pFROM  (    SELECT t1.f + t2.f AS f, t1.p * t2.p AS p    FROM      l2 t1,      (        SELECT f, SUM (p) AS p        FROM          (            SELECT t1.f + t2.f AS f, t1.p * t2.p AS p            FROM              l1 t1,              (                SELECT f, SUM (p) AS p                FROM                (                  SELECT t1.f + t2.f AS f, t1.p * t2.p AS p                  FROM                    l0 t1,                    (                      (                        SELECT 0 AS f, 1 AS p                        FROM DUAL                      )                    ) t2                )              GROUP BY f            ) t2          )        GROUP BY f      ) t2  )GROUP BY fThe above statement is actually generated in a series of small steps. Here are the clauses of the above SQL query sorted by step number and clause number.
   SECTION    CLAUSE# CLAUSE---------- ---------- ----------------------------------------         1          1 WITH l0 as(SELECT face_value as f,probab                      ility as p FROM die)         2          1 ,l1 AS(SELECT f,SUM(p) AS p FROM(SELECT                      t1.f+t2.f AS f, t1.p*t2.p AS p FROM l0 t                      1,l0 t2)GROUP BY f)         2          2 ,l2 AS(SELECT f,SUM(p) AS p FROM(SELECT                      t1.f+t2.f AS f, t1.p*t2.p AS p FROM l1 t                      1,l1 t2)GROUP BY f)         3          1 SELECT f,sum(p) AS p FROM(SELECT t1.f+t2                      .f AS f,t1.p*t2.p AS p FROM l2 t1,(         3          2 SELECT f,sum(p) AS p FROM(SELECT t1.f+t2                      .f AS f,t1.p*t2.p AS p FROM l1 t1,(         3          3 SELECT f,sum(p) AS p FROM(SELECT t1.f+t2                      .f AS f,t1.p*t2.p AS p FROM l0 t1,(         4          1 (SELECT 0 AS f, 1 AS p FROM dual)         5          1 )t2)GROUP BY f         5          2 )t2)GROUP BY f         5          3 )t2)GROUP BY fEnough said. Here is the complete solution. As usual, common table expressions are used for readability. In the first step, I generate the first section of the dynamically generated SQL statement. The fake CARDINALITY hint is required because you will encounter an ORA-600 with argument 15160 if the number of throws is extremely large and the expected cost is extremely high; we have therefore to trick the query optimizer into thinking that the table Die has only one row.
view plaincopy to clipboardprint?

  • section1 AS
  • (   

  • SELECT 1 AS
    section,   
  •        1 AS clause#,   

  • 'WITH l0 as(SELECT/*+CARDINALITY(die 1)*/face_value as f,probability as p FROM die)'
    AS clause   

  • FROM DUAL   
  • )  

section1 AS(SELECT 1 AS section,       1 AS clause#,       'WITH l0 as(SELECT/*+CARDINALITY(die 1)*/face_value as f,probability as p FROM die)' AS clause  FROM DUAL)In the following step, I generate the second section of the dynamically generated SQL statement. Each common table expression generated in this section is constructed by joining the preceding expression with itself. For example, l1 = l0 CROSS JOIN l0 and l2 = l1 CROSS JOIN l1.
view plaincopy to clipboardprint?

  • section2 AS
  • (   

  • SELECT 2 AS
    section,   

  • LEVEL
    AS clause#,   

  • ',l' || TO_CHAR (LEVEL) || ' AS(SELECT f,SUM(p) AS p FROM(SELECT t1.f+t2.f AS f, t1.p*t2.p AS p FROM l' || TO_CHAR (LEVEL - 1) || ' t1,l' || TO_CHAR (LEVEL - 1) || ' t2)GROUP BY f)'
    AS clause   

  • FROM DUAL   

  • CONNECT
    BY POWER (2, LEVEL) <= :n   
  • )  

section2 AS(SELECT 2 AS section,       LEVEL AS clause#,       ',l' || TO_CHAR (LEVEL) || ' AS(SELECT f,SUM(p) AS p FROM(SELECT t1.f+t2.f AS f, t1.p*t2.p AS p FROM l' || TO_CHAR (LEVEL - 1) || ' t1,l' || TO_CHAR (LEVEL - 1) || ' t2)GROUP BY f)' AS clause  FROM DUALCONNECT BY POWER (2, LEVEL) <= :n)In the following step, I generate the third section of the dynamically generated SQL statement. The BITAND function is used to extract the bits from the binary representation of N—the number of throws. Notice the use of the DESC clause in the ORDER BY specification.
view plaincopy to clipboardprint?

  • section3 AS
  • (   

  • SELECT 3 AS
    section,   
  •        ROW_NUMBER() OVER (ORDER
    BY
    LEVEL
    DESC) AS clause#,   
  •        DECODE (BITAND (:n, POWER (2, LEVEL - 1)), 0, '', 'SELECT f,sum(p) AS p FROM(SELECT t1.f+t2.f AS f,t1.p*t2.p AS p FROM l' || TO_CHAR (LEVEL - 1) || ' t1,(') AS clause   

  • FROM DUAL   

  • CONNECT
    BY POWER (2, LEVEL - 1) <= :n   
  • )  

section3 AS(SELECT 3 AS section,       ROW_NUMBER() OVER (ORDER BY LEVEL DESC) AS clause#,       DECODE (BITAND (:n, POWER (2, LEVEL - 1)), 0, '', 'SELECT f,sum(p) AS p FROM(SELECT t1.f+t2.f AS f,t1.p*t2.p AS p FROM l' || TO_CHAR (LEVEL - 1) || ' t1,(') AS clause  FROM DUALCONNECT BY POWER (2, LEVEL - 1) <= :n)In the following step, I generate the fourth section of the dynamically generated SQL statement. I construct an “identity” table that contains only one row and does not affect the table to which it is joined.
view plaincopy to clipboardprint?

  • section4 AS
  • (   

  • SELECT 4 AS
    section,   
  •        1 AS clause#,   

  • '(SELECT 0 AS f, 1 AS p FROM dual)'
    AS clause   

  • FROM DUAL   
  • )  

section4 AS(SELECT 4 AS section,       1 AS clause#,       '(SELECT 0 AS f, 1 AS p FROM dual)' AS clause  FROM DUAL)In the following step, I generate the fifth and final section of the dynamically generated SQL statement. I generate closing parentheses to match the opening parentheses generated in section 3.
view plaincopy to clipboardprint?

  • section5 AS
  • (   

  • SELECT 5 AS
    section,   
  •        ROW_NUMBER() OVER (ORDER
    BY
    LEVEL) AS clause#,   
  •        DECODE (BITAND (:n, POWER (2, LEVEL - 1)), 0, '', ')t2)GROUP BY f') AS clause   

  • FROM DUAL   

  • CONNECT
    BY POWER (2, LEVEL - 1) <= :n   
  • )  

section5 AS(SELECT 5 AS section,       ROW_NUMBER() OVER (ORDER BY LEVEL) AS clause#,       DECODE (BITAND (:n, POWER (2, LEVEL - 1)), 0, '', ')t2)GROUP BY f') AS clause  FROM DUALCONNECT BY POWER (2, LEVEL - 1) <= :n)I now collect clauses from all five sections. Empty clauses are eliminated and row numbers are assigned to the remaining clauses.
view plaincopy to clipboardprint?

  • all_sections AS
  • (   

  • SELECT ROW_NUMBER() OVER (ORDER
    BY
    section, clause#) AS clause#,   
  •        clause   

  • FROM (SELECT
    section, clause#, clause FROM section1 UNION
    ALL

  • SELECT
    section, clause#, clause FROM section2 UNION
    ALL

  • SELECT
    section, clause#, clause FROM section3 UNION
    ALL

  • SELECT
    section, clause#, clause FROM section4 UNION
    ALL

  • SELECT
    section, clause#, clause FROM section5)   

  • WHERE LENGTH(clause) != 0   
  • )  

all_sections AS(SELECT ROW_NUMBER() OVER (ORDER BY section, clause#) AS clause#,       clause  FROM (SELECT section, clause#, clause FROM section1 UNION ALL        SELECT section, clause#, clause FROM section2 UNION ALL        SELECT section, clause#, clause FROM section3 UNION ALL        SELECT section, clause#, clause FROM section4 UNION ALL        SELECT section, clause#, clause FROM section5) WHERE LENGTH(clause) != 0)Next, all SQL clauses are concatentated into a single VARCHAR2 string using the CONNECT BY method. The reason why I used short variable names and avoided any unnecessary white space while constructing SQL clauses is that the maximum length of a VARCHAR2 column is 2048 characters. This is the physical limitation to which I alluded earlier.
view plaincopy to clipboardprint?

  • sql_text AS
  • (   

  • SELECT
    REPLACE (sql_text, '|', '') AS sql_text   

  • FROM (SELECT RANK () OVER (ORDER
    BY lvl DESC) AS RANK,   
  •                sql_text   

  • FROM (SELECT
    LEVEL
    AS lvl,   
  •                        SYS_CONNECT_BY_PATH (clause, '|') AS sql_text   

  • FROM all_sections   
  •                 START WITH clause# = 1   

  • CONNECT
    BY clause# = LEVEL))   

  • WHERE RANK = 1   
  • )  

sql_text AS(SELECT REPLACE (sql_text, '|', '') AS sql_text  FROM (SELECT RANK () OVER (ORDER BY lvl DESC) AS RANK,               sql_text          FROM (SELECT LEVEL AS lvl,                       SYS_CONNECT_BY_PATH (clause, '|') AS sql_text                  FROM all_sections                START WITH clause# = 1                CONNECT BY clause# = LEVEL)) WHERE RANK = 1)I now execute the dynamically generated SQL statement using the DBMS_XMLGET.GETXMLTYPE function. The result is a CLOB containing the results formatted using XML.
view plaincopy to clipboardprint?

  • xml_string AS
  • (   

  • SELECT DBMS_XMLGEN.getxmltype (sql_text) xml_string   

  • FROM sql_text   
  • )  

xml_string AS(SELECT DBMS_XMLGEN.getxmltype (sql_text) xml_string  FROM sql_text)Finally, I use the XMLTABLE function to extract the results of the dynamically generated SQL statement from the XML string.
view plaincopy to clipboardprint?

  • SELECT
    sum,   
  •        probability   

  • FROM xml_string,   
  •        XMLTABLE   
  •        (   

  • '$x/ROWSET/ROW' PASSING xml_string AS
    "x"
  •          COLUMNS   

  • sum NUMBER PATH 'F',   
  •            probability NUMBER PATH 'P'
  •        ) x   

  • ORDER
    BY
    sum

SELECT sum,       probability  FROM xml_string,       XMLTABLE       (         '$x/ROWSET/ROW' PASSING xml_string AS "x"         COLUMNS           sum NUMBER PATH 'F',           probability NUMBER PATH 'P'       ) xORDER BY sumIt’s not very pretty but I was quite pleased with myself at the time. I had no idea that there were so many good solutions out there. Congratulations to Laurent Schneider (Switzerland), Craig Martin (USA), Rob van Wijk (Netherlands), Vadim Tropashko (USA), Alberto Dell’Era (Italy), Fabien Contaminard (France), Cd-MaN (Romania), and André Araujo (Australia) for their original solutions. Congratulations especially to Alberto Dell’Era, Knight of the August Order of the Wooden Pretzel!
P.S. Here is a graph of the results I obtained on my laptop with a 2.00 GHz Intel Core2 processor.

Throws (Thousands)Elapsed Time (Minutes)
10.49
21.62
33.49
45.94
59.27
613.97
720.33
933.15
1043.77




Categories: NoCOUG, Oracle, SQL

使用道具 举报

回复
论坛徽章:
50
2014年世界杯参赛球队: 荷兰
日期:2014-07-11 07:56:59蛋疼蛋
日期:2012-03-06 07:22:542012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-01-04 11:53:29蛋疼蛋
日期:2011-11-11 15:47:00ITPUB十周年纪念徽章
日期:2011-11-01 16:23:26
18#
发表于 2009-9-15 21:39 | 只看该作者
NEWKID兄,你要参赛,一定能获奖的!!!

使用道具 举报

回复
论坛徽章:
87
2015年新春福章
日期:2015-03-06 11:58:182010广州亚运会纪念徽章:轮滑
日期:2010-09-23 17:19:212010年世界杯参赛球队:乌拉圭
日期:2010-07-14 17:54:242010年世界杯参赛球队:美国
日期:2010-06-30 13:13:582010年世界杯参赛球队:墨西哥
日期:2010-06-25 12:49:452010年世界杯参赛球队:墨西哥
日期:2010-04-05 10:23:502010新春纪念徽章
日期:2010-03-01 11:06:232010新春纪念徽章
日期:2010-01-04 08:33:08生肖徽章2007版:龙
日期:2009-11-12 16:31:13参与WIN7挑战赛纪念
日期:2009-11-09 11:50:09
19#
发表于 2009-9-15 21:45 | 只看该作者
学习啊

使用道具 举报

回复
论坛徽章:
10
2009日食纪念
日期:2009-07-22 09:30:00雪佛兰
日期:2013-12-18 22:21:22Jeep
日期:2013-12-04 21:41:402013年新春福章
日期:2013-05-27 10:23:002013年新春福章
日期:2013-05-27 10:23:002013年新春福章
日期:2013-05-27 10:23:00双黄蛋
日期:2013-01-13 23:04:422012新春纪念徽章
日期:2012-01-04 11:54:26双黄蛋
日期:2011-06-23 12:19:162014年新春福章
日期:2014-03-24 22:47:17
20#
发表于 2009-9-15 22:31 | 只看该作者
额,看了傅里叶好亲切,想起了俺的大学

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表