转眼就是圣诞的节日,祝大家节日快乐。用 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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。