Oracle查询统计的时候,值无法传入,在线坐等
因为牵涉的表连接太多了,就只用的临时表作为查询主表
临时表t有product_id,year,product_name,plan_name,batch_name,first_login_time,
is_graduated,is_degree,product_type_code这几个字段,我要根据不同条件来统计不同的人数,
我的统计sql如下:
select PRODUCT_ID,YEAR,PRODUCT_NAME,PLAN_NAME,BATCH_NAME,nvl(count(*),'0') APPLY_NUM,'高等学历提升' as PRODUCT_CATEGORY_NAME,PRODUCT_TYPE_CODE
,nvl((
select count(1) from t where t.FIRST_LOGIN_DATE is not null group by YEAR,PRODUCT_ID having t.YEAR=YEAR and t.PRODUCT_ID=PRODUCT_ID
),'0') as ATTEND_NUM
,nvl((
select count(1) from t where t.IS_GRADUATED='是' group by YEAR,PRODUCT_ID having t.YEAR=YEAR and t.PRODUCT_ID=PRODUCT_ID
),'0') as GRADUATE_NUM
,nvl((
select count(1) from t where t.IS_DEGREE='是' group by YEAR,PRODUCT_ID having t.YEAR=YEAR and t.PRODUCT_ID=PRODUCT_ID
),'0') as DEGREE_NUM
from t
group by PRODUCT_ID,YEAR,PRODUCT_NAME,PLAN_NAME,BATCH_NAME,PRODUCT_TYPE_CODE
order by YEAR desc
其中YEAR和PRODUCT_ID为查询出来的值再传入统计字段过滤,现在问题是YEAR和PRODUCT_ID无法传入,这样就一直报一对多的错误,求正确的sql的写法。
------解决方案--------------------
SQL好长...
------解决方案--------------------你子查询里面用到having那结果应该是多条数据, 列的子查询只能有一行一列的数据。 你看下是不是这个问题!