@admin 在 叮~您有一封国庆SQL闯关邀请函,请查收 中说:
2022-10-01
第一关:
-- 闯关第一关
select concat(right(attr,2),SUBSTRING(attr,3,2)) from level1
效果:
第二关:
-- 闯关第二关
-- 闯关第二关
WITH d AS (
SELECT row_number() OVER (PARTITION BY attr ORDER BY attr) rn,
CASE WHEN attr='国' THEN '国'END gou,
CASE WHEN attr='庆' THEN '庆' END qing,
CASE WHEN attr='快' THEN '快' END kuai,
CASE WHEN attr='乐' THEN '乐' END lei
FROM level2
)
select concat(lpad(ss."标号",2,'0') ,' | ',ss."国",' ',ss."庆",' ',ss."快",' ',ss."乐")chart from(
select cast(row_number() over(order by t."庆" desc) as varchar) "标号",t.* from(
SELECT
case when min(gou)='国' then '国' else ' ' end "国",
case when min(qing)='庆' then '庆' else ' ' end "庆",
case when min(kuai)='快' then '快' else ' ' end "快",
case when min(lei)='乐' then '乐' else ' ' end "乐"
FROM d
GROUP BY rn
ORDER BY 国 ASC, 庆 ASC, 快 ASC, 乐 ASC)t)ss
union all select '-------------------'
union all select ' 2022-10-01'
效果: