iT邦幫忙

第 11 屆 iT 邦幫忙鐵人賽

DAY 1
4
WITH centers AS (
SELECT angle
     , len
     , ROUND(len * SIN(2 * PI() * angle)) AS x
     , ROUND(len * COS(2 * PI() * angle)) AS y
     , ROUND(len * 0.3)::INTEGER + 1 AS trace
  FROM (SELECT RANDOM() AS angle
             , 8 * (1 - POWER(RANDOM(), 3)) AS len
          FROM generate_series (1, 50) s
        ) q
),
traces AS (
SELECT *
     , generate_series(1, trace) AS part
  FROM centers
),
parts AS (
SELECT CASE
        WHEN trace = part THEN
         LEAST(len * 0.2, 2)::INTEGER
        ELSE
          TRUNC(angle * 8 - 0.5)::INTEGER % 4 + 3
       END AS symbol
     , TRUNC(x + part * SIN(2 * PI() * angle)) AS x
     , TRUNC(y + part * COS(2 * PI() * angle)) AS y
  FROM traces
)
SELECT ARRAY_TO_STRING(ARRAY(
       SELECT COALESCE((
              SELECT SUBSTR('.??\\-/|', MIN(symbol) + 1, 1)
                FROM parts
               WHERE x = col - 14
                 AND y = row - 12
              ), ' ')
         FROM generate_series(1, 25) col
        ), '') AS FIREWORKS
   FROM generate_series(1, 24) row;

result:
https://ithelp.ithome.com.tw/upload/images/20190916/2005064783ODa6iPP8.png

上面的SQL Command中使用了emoji,貼的時候有正常顯示,發表時變成問號了...
不過沒關係, 若要複製時,可以自行修正. 到以下網址,可以複製.
https://emojipedia.org/moon-cake/
https://emojipedia.org/full-moon-symbol/


下一篇
Postgresql 一些基本資料的查詢方式
系列文
以Postgresql為主,聊聊資料庫.30

尚未有邦友留言

立即登入留言