IF条件判断可以在sql里这样用吗

SELECT

${if(type=="1"," 字段A * 10 ")} as 字段别名,

AMT,

WT,

PRICE

FROM 表名

如果传的type参数等于1,就让这个字段乘以10

SELECT 

A."YMON",

A."wt",

${if(type=="1"," A."wt" * 10 "," A."wt" ")} AS "wt2",

FROM 

(SELECT 

LEFT(CUR_DAY,6) AS "YMON",

DECIMAL(ROUND(SUM(DISTINCT DAY_OUTPUT_WT),1),12,1) AS "wt"

FROM BGTMMAKS01.T_ADS_SRV_KSCB_DAY_COST

WHERE (LEFT(CUR_DAY,6) BETWEEN '202311' AND '202311' OR LEFT(CUR_DAY,6) BETWEEN  '202312' AND '202312')

AND COST_CENTER IN ('ABB0','ABJ0')

GROUP BY LEFT(CUR_DAY,6)) AS A

----------------

${if(type=="1"," A.wt * 10 "," A.wt ")} AS "wt2",

FineReport vTVzmj 发布于 2024-1-17 16:50 (编辑于 2024-1-17 17:10)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2024-1-17 16:51(编辑于 2024-1-17 16:52)

else 呢??

-------

SELECT

${if(type=="1"," 字段A * 10 ","不为1时怎么处理")} as 字段别名,

AMT,

WT,

PRICE

FROM 表名

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