给特定字段取负数

qq_36934345 2017-05-19 09:14:02
怎么去写一个,指定的代码对应的数据加个负号,比如挣到的钱为a,付出的钱为b,最后要算盈亏,我就要在付出的数据上加个负号才好算我用的是12C,盈负在一个字段里面的不同代码,有多个代码表示盈负,数据量很大直接减法不现实,跪求各位大神...
...全文
467 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_36934345 2017-05-19
  • 打赏
  • 举报
回复
引用 9 楼 wmxcn2000 的回复:
[quote=引用 7 楼 qq_36934345 的回复:] select A,B,C from table where a.1=b.1 and ..... and.... and ( case when jymc in ('01'.'02'.'03''.....) then -jymc else jymc end) group by A,B,C; 一直报错....
把建表语句,和你的 查询 语句,都完整的贴出来;你这一句半句的,看不出来;[/quote]

select B.GH,nvl(b.sfzh,b.jbxx_zjhm) as sfzh,b.gmc,b.jbxx,b.xm, b.xx_xb,b.xx_nl,b.xx_khjb,c.WH_XM,a.jydm,a.jymc,a.jyje,a.cq from
          cxjylsb_ls a,
         hxb_and_zb b,
          gryxxt_jbxxb c
  where (nvl(b.sfzh,b.jbxx_zjhm)=c.jd_zjhm(+) and nvl(b.sfzh,b.jbxx_zjhm)=a.sfzh(+)) 
  and (substr(a.jysj,1,10)>='2017-04-15' and substr(a.jysj,1,10)<='2017-04-22')
    and jymc is not null
     and (case when jymc in
       ('01','02','03','04','05') then -jyje
            else jyje
         end)
   group by B.GH,nvl(b.sfzh,b.jbxx_zjhm) as sfzh,b.gmc,b.jbxx,b.xm, b.xx_xb,b.xx_nl,b.xx_khjb,c.WH_XM,a.jydm,a.jymc,a.jyje,a.cq;




jdsnhan 2017-05-19
  • 打赏
  • 举报
回复
你select A B C 然后 group by A B C,这是想干啥啊
卖水果的net 2017-05-19
  • 打赏
  • 举报
回复
引用 7 楼 qq_36934345 的回复:
select A,B,C from table where a.1=b.1 and ..... and.... and ( case when jymc in ('01'.'02'.'03''.....) then -jymc else jymc end) group by A,B,C; 一直报错....
把建表语句,和你的 查询 语句,都完整的贴出来;你这一句半句的,看不出来;
kopala 2017-05-19
  • 打赏
  • 举报
回复
看不懂题目 sum(decode(jymc,'01',jymc ,'04',-jymc)) 这样可以吗?
qq_36934345 2017-05-19
  • 打赏
  • 举报
回复
select A,B,C from table where a.1=b.1 and ..... and.... and ( case when jymc in ('01'.'02'.'03''.....) then -jymc else jymc end) group by A,B,C; 一直报错....
qq_36934345 2017-05-19
  • 打赏
  • 举报
回复
引用 5 楼 wmxcn2000 的回复:
可以的 case when sum(cc) > 0 then '正' else '负' end 或者用 sign(sum(cc)) 也可以
这个case when 插放哪里啊 我where 后面跟了几个and条件语句,放在and后面一直报错ora-00920...
卖水果的net 2017-05-19
  • 打赏
  • 举报
回复
可以的 case when sum(cc) > 0 then '正' else '负' end 或者用 sign(sum(cc)) 也可以
qq_36934345 2017-05-19
  • 打赏
  • 举报
回复
引用 3 楼 wmxcn2000 的回复:
-- case when 可以解决你的问题吗? case when jymc in ('01'.'02'.'03''.....) then -jymc else jymc end
能,我试一下,那在查询里面算盈负可以直接SUM(jymc)判断正负来算盈负么...
卖水果的net 2017-05-19
  • 打赏
  • 举报
回复
-- case when 可以解决你的问题吗? case when jymc in ('01'.'02'.'03''.....) then -jymc else jymc end
qq_36934345 2017-05-19
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
说说你现在的表结构,并给出部分测试数据;
可不可以这样select number(jymc in ('01'.'02'.'03''.....) - jymc in ('04'.'05'.'06''.....)) ,count(*)....01,02,03为挣得数据,040506为付出的,有没有这样的写法
卖水果的net 2017-05-19
  • 打赏
  • 举报
回复
说说你现在的表结构,并给出部分测试数据;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧