求这两条sql

image.png

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

一个提问 发一个SQL

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年月'

image.png

  • 百煮味香 百煮味香(提问者) 请问是用的mysql 吗
    2023-03-02 16:03 
  • 用户6NWif5139660 用户6NWif5139660 回复 百煮味香(提问者) 嗯嗯 我直接在 帆软的内置数据库里写的。 mysql也能用
    2023-03-02 16:04 
  • 2关注人数
  • 170浏览人数
  • 最后回答于:2023-3-2 15:19
    请选择关闭问题的原因
    确定 取消
    返回顶部