SQL两个表,两个参数判断

SELECT

PROJECT_NAME AS 项目,

IF(LEN(PROJECT)==0,PROJECT_TYPE,YEAR_MONTHS) AS  分类,

NET_PROFIT_ACT AS 动态版净利润,

NET_PROFIT_TAR AS 方案版净利润,

NET_PROFIT_DEVIATION AS 净利润偏差,

NET_INTEREST_RATE_ACT AS 动态版净利率,

NET_INTEREST_RATE_TAR AS 方案版净利率,

NET_INTEREST_RATE_DEVIATION AS 净利率偏差,

CARGO_VALUE_ACT AS 动态版货值,

CARGO_VALUE_TAR AS 方案版货值,

CARGO_VALUE_DEVIATION AS 货值偏差,

CARGO_COST_ACT AS 动态版成本,

CARGO_COST_TAR AS 方案版成本,

CARGO_COST_DEVIATION AS 成本偏差

FROM 

IF(LEN(PROJECT)==0,DW_LR_FINANCE_INDEX_BY_PRO,DW_LR_FINANCE_INDEX_BY_PRO_MONTH)

WHERE

${IF(LEN(PROJECT)==0 AND TYPE !='全部项目' ,WHERE PROJECT_TYPE = '"+TYPE+"',WHERE PROJECT_NAME = '"+PROJECT+"')} 

${IF(LEN(PROJECT)==0 AND TYPE ='全部项目' ,WHERE PROJECT_NAME = '"+PROJECT+"')}

SQL 难过的过 发布于 2022-11-7 18:35
1min目标场景问卷 立即参与
回答问题
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
难过的过Lv3见习互助
发布于2022-11-8 08:47

SELECT

PROJECT_NAME AS 项目,

${IF(LEN(PROJECT)==0,"PROJECT_TYPE","YEAR_MONTHS")} AS 分类,

NET_PROFIT_ACT AS 动态版净利润,

NET_PROFIT_TAR AS 方案版净利润,

NET_PROFIT_DEVIATION AS 净利润偏差,

NET_INTEREST_RATE_ACT AS 动态版净利率,

NET_INTEREST_RATE_TAR AS 方案版净利率,

NET_INTEREST_RATE_DEVIATION AS 净利率偏差,

CARGO_VALUE_ACT AS 动态版货值,

CARGO_VALUE_TAR AS 方案版货值,

CARGO_VALUE_DEVIATION AS 货值偏差,

CARGO_COST_ACT AS 动态版成本,

CARGO_COST_TAR AS 方案版成本,

CARGO_COST_DEVIATION AS 成本偏差

FROM 

${IF(LEN(PROJECT)==0,"DW_LR_FINANCE_INDEX_BY_PRO","DW_LR_FINANCE_INDEX_BY_PRO_MONTH")}

${IF(LEN(PROJECT)==0 && TYPE ='全部项目'," WHERE PROJECT_NAME = '"+PROJECT+"'","")}

${IF(LEN(PROJECT)==0 && TYPE !='全部项目'," WHERE PROJECT_NAME = '"+PROJECT+"' AND  PROJECT_TYPE = '"+TYPE+"'","")}

最佳回答
0
luojian0323Lv7资深互助
发布于2022-11-7 18:52(编辑于 2022-11-7 18:53)

你的写法错误。

image.png

参考

  • 1关注人数
  • 272浏览人数
  • 最后回答于:2022-11-8 08:47
    请选择关闭问题的原因
    确定 取消
    返回顶部