oracle 查询select sum (case when then t1.se else 0 end) as senygzxx, from xxs t1,bjs t2 怎么写正确

select sum (case when t1.year='2013' and t1.cxlb in ('111','112','121','122','123','210','220') then t1.senygzxx else 0 end) as senygzxx, sum (case when t2.year='2013'and t2.jieduan in ('3','4') and t2.lb1='总计' then t2.cyinj+***.cern... select sum (case when t1.year='2013' and t1.cxlb in ('111','112','121','122','123','210','220') then t1.senygzxx else 0 end) as senygzxx, sum (case when t2.year='2013'and t2.jieduan in ('3','4') and t2.lb1='总计' then t2.cyinj+***.cernj+t2.csannj+t2.csinj+t2.gyinj+t2.gernj+t2.gsannj else 0 end) as bjsfrom xxs t1,bjs t2
网友 1

最佳答案

回答者:网友
Case when 的用法,简单Case函数
简单CASE表达式,使用表达式确定返回值.
  语法:
  CASE search_expression
  WHEN expression1 THEN result1
  WHEN expression2 THEN result2
  ...
  WHEN expressionN THEN resultN
  ELSE default_result
搜索CASE表达式,使用条件确定返回值.
  语法:
  CASE
  WHEN condition1 THEN result1
  WHEN condistion2 THEN result2
  ...
  WHEN condistionN THEN resultN
  ELSE default_result
END

我来回答