麻烦前辈有这两条sql的话上传一下sql脚本呗

image.png

a282e9b1f0ac27bfddb293d7893de4f.png

FineReport 百煮味香 发布于 2023-3-2 16:13 (编辑于 2023-3-2 17:46)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
用户6NWif5139660Lv6资深互助
发布于2023-3-2 16:19

select d.*,case when (d.同期增长值*1.00/d.'2020当月销量'*1.00) is null then 0 else (d.同期增长值*1.00/d.'2020当月销量'*1.00) end 同比 from 

(select c.yearmonth '2020年月',c.saleamount '2020当月销量',b.yearmonth '2021年月',b.saleamount '2021当月销量',

b.saleamount - c.saleamount 同期增长值 from

(select * from (

select a.*,substr(a.yearmonth,0,5) year,substr(a.yearmonth,6,2) month

 from sql2003 a

join 

(select *,substr(yearmonth,0,5) year,substr(yearmonth,6,2) month from sql2003) b on a.yearmonth = b.yearmonth)

where year = '2020') c

join

(select * from (

select a.*,substr(a.yearmonth,0,5) year,substr(a.yearmonth,6,2) month

 from sql2003 a

join 

(select *,substr(yearmonth,0,5) year,substr(yearmonth,6,2) month from sql2003) b on a.yearmonth = b.yearmonth)

where year = '2021') b where b.month = c.month) d order by d.'2020年月'

=======================

SELECT

a.yearmonth 年月,

a.saleamount 当月销量,

case when (( a.saleamount - a.前一月销量 ) * 1.00 / a.前一月销量 * 1.00) is null then 0 else (( a.saleamount - a.前一月销量 ) * 1.00 / a.前一月销量 * 1.00) end 环比 

FROM

( SELECT *, lag( coalesce( saleamount, 0 ), 1 ) OVER ( ORDER BY yearmonth ) 前一月销量 FROM sql2003 ) a 

ORDER BY

yearmonth

最佳回答
0
qtLv6见习互助
发布于2023-3-2 16:16

https://www.zhihu.com/zvideo/1495894942165270528

  • 3关注人数
  • 286浏览人数
  • 最后回答于:2023-3-2 17:46
    请选择关闭问题的原因
    确定 取消
    返回顶部