sql 如下
select
session_id,
substr(LOGIN_TIME,1,14)||'00' TIME_ID,
LOGIN_TIME,
(select max(LOGIN_TIME) from foc_session where USER_ID=t.USER_ID and LOGIN_TIME<t.LOGIN_TIME) LAST_LOGIN_TIME,
0,
DISTRICT_ID,
AGE_ID,
JOB_ID,
ASSETS_ID,
VISIT_FLAG,
SEX_ID,
coalesce(SCREEN_ID,'99'),
ORG_ID,
to_char(to_date(substr(login_time,1,10),'YYYY-MM-DD'),'D')-1 WEEK_ID ,
(select sum(REMAIN_TIME) from FOC_TRAN_MKT_ALL_ACTION where session_id=t.session_id) REMAIN_TIME,
coalesce(BROWSER_ID,'99'),
coalesce(OS_ID,'99'),
EDUCATE_ID,
USER_ID CUST_ID,
sum(COUNTFOCID) COUNT_PV,
sum((select sum(case SESSION_FLOG when '2' then 1 else 0 end) QUIT_FLAG from FOC_TRAN_MKT_ALL_ACTION where session_id=t.session_id)) COUNT_OUTOF
from FOC_TRAN_MKT_ALL_SESSION t
group by
session_id,
LOGIN_TIME,
DISTRICT_ID,
AGE_ID,
JOB_ID,
ASSETS_ID,
VISIT_FLAG,
SEX_ID,
SCREEN_ID,
ORG_ID,
logout_time,
BROWSER_ID,
OS_ID,
EDUCATE_ID,
USER_ID;
报错如下
SQL0112N The operand of the column function "SYSIBM.SUM" includes a column function, a scalar fullselect, or a subquery. SQLSTATE=42607
我知道问题出在
sum((select sum(case SESSION_FLOG when '2' then 1 else 0 end) QUIT_FLAG from FOC_TRAN_MKT_ALL_ACTION where session_id=t.session_id)) COUNT_OUTOF
这一行,但不知道怎么解决,求高手
5 个解决方案
#1
在线等DB2 高手出现
#2
这段sql 是从oracle 转过来的,DB2貌似不支持sum()的这种嵌套使用,要用什么方法替代啊
#3
没有看到记录,试试
...
sum(case SESSION_FLOG when '2 ' then 1 else 0 end)
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
...
...
sum(case SESSION_FLOG when '2 ' then 1 else 0 end)
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
...
#4
谢谢LS的,但没看明白你的意思,你是怎样去掉一个SUM() 的?
#5
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
测试一下结果,如果不对,还要修改
#1
在线等DB2 高手出现
#2
这段sql 是从oracle 转过来的,DB2貌似不支持sum()的这种嵌套使用,要用什么方法替代啊
#3
没有看到记录,试试
...
sum(case SESSION_FLOG when '2 ' then 1 else 0 end)
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
...
...
sum(case SESSION_FLOG when '2 ' then 1 else 0 end)
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
...
#4
谢谢LS的,但没看明白你的意思,你是怎样去掉一个SUM() 的?
#5
from FOC_TRAN_MKT_ALL_SESSION t inner join FOC_TRAN_MKT_ALL_ACTION c on c.session_id=t.session_id
测试一下结果,如果不对,还要修改