试试
select 编码,sum(数量) from 表名 having 编码 in (select 编码 from 表名 where 编码 like 编码) group by 编码;
select 编码,sum(数量) from 表名 having 编码 in (select 编码 from 表名 where 编码 like 编码) group by 编码;
解决方案 »
- jdbc更新oracle数据库后,数据库中的记录没变
- 这个SQl语句有点难写,不会写~~呵呵,选择问题
- ORACLE 记录更改排序
- oracle安装时为断网状态,后来联网后数据库oracledbconsoleorcl出现2错误
- 送分了~~
- 请教大家一个问题,希望能够解决,想出个好的办法来!
- 难题!“移动加权平均成本”计算的SQL的写法。(证券成本计价)
- 请问:数据库显示"high parse to execute ratio"是什么意思?
- 大家看看这个语句怎么优化?谢谢!
- 高分征集算法
- linux字符问题
- Unix下的weblogic7访问Windows2000server下的Oracle的中文字符乱码问题?
首先你先想想,编码 like 编码,起不到任何作用,在本题中是为真的。
那么子查询会把所有编码列出来,那么最后你的语句相当于
select 编码,sum(数量) from 表名 group by 编码;
这对吗??
本来你热心回答问题,我不应该冷嘲热讽,但是我实在看不下去有人不负责任。
如果言语唐突,请见谅!!
在此呼吁ORACLE版倡导良好的回答问题的态度,最起码先测试过再发。如果没有
测试环境,请注明“未经测试!”。
--明确知道只有三层!
如果对你的数据也成立的话,我给出一个比较复杂的sql,不算完美。
select substr(id,1,2) id,sum(nvl(sl,0)) sl from tt
group by substr(id,1,2)
union
select substr(id,1,4) id,sum(nvl(sl,0)) sl from tt
where length(id) > 2 group by substr(id,1,4)
union
select substr(id,1,6) id,sum(nvl(sl,0)) sl from tt
where length(id) >4 group by substr(id,1,6);
我这里写了一个sql,大家来看看有什么问题
select code ,(select count(1) from table where where code like t.code||'%') from
table t
from tab b where a.编码 = Substr(b.编码, 1, length(a.编码))
from table a
首先非常感谢你回答我的问题:),你这种写法只是汇总一层。我写那种已经解决了。可以汇总n层节点数