您好,登錄后才能下訂單哦!
轉眼就是圣誕的節日,祝大家節日快樂。用 GaussDB T (也就是 GaussDB 100)繪制一棵圣誕樹,純國產,更喜慶。
話不多說,上圖:
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 "圣誕快樂!"
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 中執行效果如下:
總結一下,在使用了非常特殊的查詢語法后,GaussDB 工作的非常愉快:
Case When;
LAG 分析函數;
CONNECT by;
當然,楊長老說了,我這棵圣誕樹不太好看,他根據公司的祝賀圖重新畫了一個,楊長老說圣誕樹應該是這樣的:
再來圖:
上代碼:
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;
祝大家圣誕快樂,萬事如意,平平安安!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。