select *
from (select 0 as id,'050003' as MARKETCODE,'' as SEQCODE,'' as ACCOUNT,'' as ACCNAME,'' as CCADDR,
max(BALDATE) as BALDATE,'' as CURRENCY,0 as BALANCE,to_number(sum(BALANCEAVAL)) as BALANCEAVAL,
'' as CKECKSTATUS,max(UPDATEUSER) as UPDATEUSER, max(UPDATETIME) as UPDATETIME,max(CHECKUSER) as CHECKUSER,
max(CHECKTIME) as CHECKTIME
from srv_koss_accbalance where baldate='20180619' and marketcode='050003' and account!='310066726018150009956' )
where exists (select * from srv_koss_accbalance where marketcode='050003' and account!='310066726018150009956')
exists():表示()内子查询语句返回结果不为空说明where条件成立就会执行主sql语句,如果为空就表示where条件不成立,sql语句就不会执行。
not exists和exists相反。
写法:select * from (SQL查询语句) where exists(SQL查询语句)
exists后面的sql是判断这个大的sql生不生效,生效的话,真正的返回结果是from后面sql的返回结果。
例子:select * from 表名 where exists(判断sql) and 真正执行的where条件
select * from srv_koss_fundinfo x where exists(SELECT *FROM SRV_KOSS_FUNDINFO WHERE FUNDTYPE='6') and FUNDTYPE='3'