轉(zhuǎn)眼就是圣誕的節(jié)日,祝大家節(jié)日快樂(lè)。用 GaussDB T (也就是 GaussDB 100)繪制一棵圣誕樹(shù),純國(guó)產(chǎn),更喜慶。
成都創(chuàng)新互聯(lián)是專業(yè)的相山網(wǎng)站建設(shè)公司,相山接單;提供做網(wǎng)站、網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行相山網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!話不多說(shuō),上圖:
SQL如下:
SELECT
CASE WHEN ENMOTECH = 1 THEN lpad('*',
GAO,
' ')
ELSE lpad(' ',
GAO + 1-ENMOTECH,
' ') || rpad('*',
lag(ENMOTECH) OVER (PARTITION BY 1
ORDER BY
ENMOTECH) + ENMOTECH -2,
'*')
END "圣誕快樂(lè)!"
FROM
(SELECT
LEVEL ENMOTECH ,
MAX(LEVEL) OVER (PARTITION BY 1) GAO
FROM dual
CONNECT BY LEVEL < 19 )
UNION ALL
SELECT
lpad(lpad('*',3,'*'),19)
FROM dual
CONNECT BY LEVEL < 5;
主要,這段 SQL 代碼,和 Oracle 完全兼容,在 Oracle 中執(zhí)行效果如下:
總結(jié)一下,在使用了非常特殊的查詢語(yǔ)法后,GaussDB 工作的非常愉快:
Case When;
LAG 分析函數(shù);
CONNECT by;
當(dāng)然,楊長(zhǎng)老說(shuō)了,我這棵圣誕樹(shù)不太好看,他根據(jù)公司的祝賀圖重新畫(huà)了一個(gè),楊長(zhǎng)老說(shuō)圣誕樹(shù)應(yīng)該是這樣的:
再來(lái)圖:
上代碼:
WITH leaf AS (
SELECT
lpad(rpad('*',
(ROWNUM-1)* 2 + 1,
'*'),
ROWNUM + 20) leaf,
ROWNUM
FROM
dual
CONNECT BY
LEVEL <= 3),
lv AS (
SELECT
ROWNUM lv
FROM
dual
CONNECT BY
LEVEL <= 5),
leafs AS (
SELECT
lpad(rpad('*',
(ROWNUM-1)* 2 + 1 +(lv-1)* 2,
'*'),
ROWNUM + 20 + lv) leaf
FROM
leaf,
lv),
root AS (
SELECT
lpad(rpad('*',
5,
'*'),
24)
FROM
dual
CONNECT BY
LEVEL <= 4)
SELECT
leaf
FROM
leafs
UNION ALL
SELECT
*
FROM
root;
祝大家圣誕快樂(lè),萬(wàn)事如意,平平安安!