After a while is the Christmas festival, I wish you a happy holiday. With GaussDB T (that is, GaussDB 100) draw a Christmas tree, pure domestic, more festive.
Without further ado, above:
SQL is as follows:
SELECT
CASE WHEN ENMOTECH = 1 THEN lpad(The '*',
GAO,
' ')
ELSE lpad(' ',
GAO + 1-ENMOTECH,
' ') || rpad(The '*',
lag(ENMOTECH) OVER (PARTITION BY 1
ORDER BY
ENMOTECH) + ENMOTECH -2,
The '*')
END "Merry Christmas!
FROM
(SELECT
LEVEL ENMOTECH ,
MAX(LEVEL) OVER (PARTITION BY 1) GAO
FROM dual
CONNECT BY LEVEL < 19 )
UNION ALL
SELECT
lpad(lpad(The '*', 3,The '*'),19)
FROM dual
CONNECT BY LEVEL < 5;
Copy the code
This SQL code is fully compatible with Oracle.
In summary, after using very special query syntax, GaussDB works very well:
The Case When; LAG analysis function; CONNECT by;Copy the code
Of course, Elder Yang said, my Christmas tree is not very beautiful, he based on the company’s congratulations to draw a new one, Elder Yang said the Christmas tree should be like this:
To:
The code:
WITH leaf AS (
SELECT
lpad(rpad(The '*',
(ROWNUM-1)* 2 + 1,
The '*'),
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(The '*',
(ROWNUM-1)* 2 + 1 +(lv-1)* 2,
The '*'),
ROWNUM + 20 + lv) leaf
FROM
leaf,
lv),
root AS (
SELECT
lpad(rpad(The '*',
5,
The '*'),
24)
FROM
dual
CONNECT BY
LEVEL <= 4)
SELECT
leaf
FROM
leafs
UNION ALL
SELECT
*
FROM
root;
Copy the code
I wish you all a merry Christmas, all the best and go in peace!
The original link: https://www.modb.pro/db/13632