首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

请问一段sql语句编写

2012-02-23 
请教一段sql语句编写求表(base)的余额(ye)。条件是:1、表中科目号(km)为1001、1002,并且标记(falg)为1;2、表中

请教一段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'

热点排行