解决方案 »
- oracle 版本 搬迁 从Oracle8i 到 11g 需要注意些什么问题?
- oracle dataguard :standby库在mount状态时,主库怎么传送日志?
- 如何在PL/SQL中执行select in查询
- 连接linux系统下的oracle92出现问题,着急!
- oracle 登录问题
- ORACLE 9I中建表的脚本都 执行了,我的表去哪里能看到啊,在(oem)中
- DBMS Job -- 关于作业运行出错,请帮忙!
- 想学Oracle,问几个基础问题。
- java.exe运行错误
- 各路高手,我想把在oracle时间字段,只提取日期部门进行加减运算,不知如何实现!请各们大虾指教,在下感激不尽!
- 定时任务 循环批次执行
- 数据库
WITH T AS (
select rn,REGEXP_SUBSTR(A, '[^,]+', 1, LEVEL) AS A,B,C
from (select A,B,C,rownum rn from MV_DWTJ)
CONNECT BY LEVEL <= REGEXP_COUNT( A, ',') + 1
and rn= prior rn
and prior dbms_random.value is not null
)
SELECT A,SUM(B),SUM(C)
FROM T GROUP BY A
select REGEXP_SUBSTR(A, '[^,]+', 1, LEVEL) A,B,C
from MV_DWTJ
CONNECT BY LEVEL <= REGEXP_COUNT(A, ',') + 1
and rowid= prior rowid
and prior dbms_random.value is not null
)
SELECT A,SUM(B),SUM(C)
FROM T GROUP BY A
另外注意你数据中的逗号是中文逗号还是英文逗号,正则表达式需要相应调整
b.code,
max(b.zh_cn_caption),
sum(a.before_income)
from
mv_dwtj a,
const_dictionary b
where
instr(a.g_chk_characteristic_name,b.zh_cn_caption) > 0
group by
b.code
/*order by
b.code */
b.code,
max(b.zh_cn_caption),
sum(a.before_income)
from
mv_dwtj a,
const_dictionary b
where
instr(a.g_chk_characteristic_name,b.zh_cn_caption) > 0
group by
b.code
/*order by
b.code */
这种方法我想过,但是因为两个表没有完全建立链接,查出来的数乘积的厉害,sum的数完全不对了……
这样是不是你想要的select
b.code,
max(b.zh_cn_caption),
sum(a.before_income)
from
mv_dwtj a,
const_dictionary b
where
instr(a.g_chk_characteristic_name,b.zh_cn_caption) > 0
group by
b.code
/*order by
b.code */
楼主,你看清楚,“其他” 在你给的截图中,就有两条,为什么是0呢
我觉得这种是正确的
这样写真的有笛卡尔乘积,是为什么呢?怎么处理
,这个sql困扰了我一下午了
你可以考虑在这个sql的基础上修改下select
b.code,
max(b.zh_cn_caption),
sum(a.before_income)
from
mv_dwtj a,
const_dictionary b
where
instr( ','||a.g_chk_characteristic_name||',',','||b.zh_cn_caption||',') > 0
group by
b.code
/*order by
b.code */