sql问题

mysql:Jan_value、feb_value、mar_value、mar_value、may_value、jun_value、api_value、aug_value、sep_value、oct_value、nov_value、dev_value以上字段对应1到12月,查询4月到8月的数据, 但是我查询的参数是1到12月阿拉伯数字,数据库是英文字段,我怎么能让他们对应上

FineReport 帆软用户arYLnKyHW7 发布于 2024-8-7 10:36
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
华莉星宸Lv7高级互助
发布于2024-8-7 10:37(编辑于 2024-8-7 10:38)

先列转行处理啊

外面在套一层就行了

------------------参考

with A as (

select YEAR,1 as Month_Column,Jan_value as value from factorypresetsproduction

union all

select YEAR,2 as Month_Column,feb_value as value from factorypresetsproduction

union all

select YEAR,3 as Month_Column,mar_value as value from factorypresetsproduction

union all

select YEAR,4 as Month_Column,apr_value as value from factorypresetsproduction

union all

select YEAR,5 as Month_Column,may_value as value from factorypresetsproduction

union all

select YEAR,6 as Month_Column,jun_value as value from factorypresetsproduction

union all

select YEAR,7 as Month_Column,api_value as value from factorypresetsproduction

union all

select YEAR,8 as Month_Column,aug_value as value from factorypresetsproduction

union all

select YEAR,9 as Month_Column,sep_value as value from factorypresetsproduction

union all

select YEAR,10 as Month_Column,oct_value as value from factorypresetsproduction

union all

select YEAR,11 as Month_Column,nov_value as value from factorypresetsproduction

union all

select YEAR,12 as Month_Column,dev_value as value from factorypresetsproduction)

select * from A where YEAR = "2024" and Month_Column BETWEEN 1 AND 8;

最佳回答
0
snrtuemcLv8专家互助
发布于2024-8-7 10:39

select * from

(SELECT 

    CASE 

         WHEN Month_Column  = 1 THEN Jan_value

        WHEN Month_Column  = 2 THEN feb_value

        WHEN Month_Column  = 3 THEN mar_value

        WHEN Month_Column  = 4 THEN mar_value

        WHEN Month_Column  = 5 THEN may_value

        WHEN Month_Column  = 6 THEN jun_value

        WHEN Month_Column  = 7 THEN api_value

        WHEN Month_Column  = 8 THEN aug_value

        WHEN Month_Column  = 9 THEN sep_value

        WHEN Month_Column  = 10 THEN oct_value

        WHEN Month_Column  = 11 THEN nov_value

        WHEN Month_Column = 12 THEN dev_value

    END AS Corresponding_Value

FROM factorypresetsproduction) a where a.YEAR = "2024" and a.Corresponding_Value BETWEEN 1 AND 8;

  • 3关注人数
  • 125浏览人数
  • 最后回答于:2024-8-7 10:39
    请选择关闭问题的原因
    确定 取消
    返回顶部