读书人

请问一段sql语句编写

发布时间: 2012-02-23 22:01:36 作者: rapoo

请教一段sql语句编写
求表(base)的余额(ye)。条件是:
1、表中科目号(km)为1001、1002,并且标记(falg)为1;
2、表中科目号(km)为1003、1004,并且标记(flag)为2.
同时满足上两个条件,写一个合成sql语句。

[解决办法]

SQL code
select yefrom basewhere (km in ('1001','1002') and flag = 1)   or (km in ('1001','1002') and flag = 1);
[解决办法]
SQL code
select yefrom basewhere (km in ('1001','1002') and flag = 1)   or (km in ('1003','1004') and flag = 2);
[解决办法]
SQL code
select case            when ye='1001' or ye='1002' then 1           when ye='1003' or ye='1004' then 2           else null       end flagfrom base
[解决办法]
1、union 集合集
2、
select sum(currbal) from dm_user.fsd_lns_fyjye
where (substr(subctrlcode,1,4)='1301' and flag='3' )
or (flag='1' and subctrlcode in ('1382001','1382005') )
and etl_date=to_date('2011-03-31','yyyy-mm-dd')

and profitbrc='01900'

读书人网 >oracle

热点推荐