首页
论坛
门户
空间
手机版
IXPUB
插件
收藏
设置
注册
登录
商店
搜索
培训
Wiki
Blog
归档
丛书
退出
ITPUB论坛
»
Oracle数据库管理
» 能解这个的,一定是SQL高手。
‹‹ 上一主题
|
下一主题 ››
38
1/4
1
2
3
4
››
投票
交易
悬赏
活动
评价
|
打印
|
推荐
|
订阅
|
收藏
标题: 能解这个的,一定是SQL高手。
lypch
初级会员
精华贴数 0
个人空间
0
技术积分 174 (10622)
社区积分 0 (123093)
注册日期 2004-7-8
论坛徽章:0
#1
使用道具
发表于 2008-7-12 11:28
能解这个的,一定是SQL高手。
LEVEL Parent Child Parent Qty Child Qty
1 A B 1 3
2 B C 2 3
3 C D 5 6
4 D E 1 2
1 A Z 1 3
A是成品
B,C,D是半成品
E,Z是原材料
从上面一个比例关系可以计算出,做一个A最终需要10.8个E和3个Z,
也就是能看到下面的结果
Parent Child QTY
A E 10.8
A Z 3
我想知道有没有什么办法通过一个SQL语句来实现这个功能。
请大家帮忙想象办法。
只看该作者
kso
Just do it!
精华贴数 0
个人空间
0
技术积分 2428 (646)
社区积分 114 (3194)
注册日期 2005-5-6
论坛徽章:17
#2
使用道具
发表于 2008-7-12 12:26
BOM结构啊。。。
__________________
执子之手,与子偕老。
只看该作者
mihawk
卡卡西
来自 杭州
精华贴数 1
个人空间
0
技术积分 1229 (1440)
社区积分 47 (5033)
注册日期 2004-12-27
论坛徽章:4
#3
使用道具
发表于 2008-7-12 13:53
只能得到算式, 等待高手出来继续.
select parent, child, '1'||x as x
from
(
select a.*, sys_connect_by_path(cqty/pqty, '*') as x
from
(
select 1 as lv, 'A' as parent, 'B' as child, 1 as pqty, 3 as cqty from dual union all
select 2 as lv, 'B' as parent, 'C' as child, 2 as pqty, 3 as cqty from dual union all
select 3 as lv, 'C' as parent, 'D' as child, 5 as pqty, 6 as cqty from dual union all
select 4 as lv, 'D' as parent, 'E' as child, 1 as pqty, 2 as cqty from dual union all
select 1 as lv, 'A' as parent, 'Z' as child, 1 as pqty, 3 as cqty from dual
) a
start with lv=1
connect by parent=prior child
)
where child in ('Z','E')
/
P C X
- - --------------------
D E 1*3*1.5*1.2*2
A Z 1*3
__________________
◆◆决定一个SQL执行效率的是执行计划, 而不是SQL的写法.◆◆
1. 数据真实的"统计"的分布情况
2. 系统视图中记录的统计信息
3. 实际每个SQL执行时对应的数据情况
只看该作者
qiuruiping
中级会员
精华贴数 0
个人空间
0
技术积分 493 (3935)
社区积分 33 (5937)
注册日期 2002-1-24
论坛徽章:0
#4
使用道具
发表于 2008-7-12 14:01
看看这里。
有9i的实现方法
http://blog.csdn.net/wzy0623/archive/2007/06/08/1644049.aspx
只看该作者
yuanfang830
初级会员
精华贴数 0
个人空间
0
技术积分 186 (10035)
社区积分 0 (638255)
注册日期 2005-10-1
论坛徽章:0
#5
使用道具
发表于 2008-7-12 14:23
SQL> select * from test_0712;
LE PARENT CHILD PA CH
-- ------ ----- -- --
1 A B 1 3
2 B C 2 3
3 C D 5 6
4 D E 1 2
1 A Z 1 3
SQL>
SQL> select t1.parent,t4.child,t1.bili*t2.bili*t3.bili*t4.bili qty from
2 (select t.parent,t.child_qty/t.parent_qty bili from test_0712 t where levell=1 ) t1,
3 (select t.child_qty/t.parent_qty bili from test_0712 t where levell=2 ) t2,
4 (select t.child_qty/t.parent_qty bili from test_0712 t where levell=3 ) t3,
5 (select t.child,t.child_qty/t.parent_qty bili from test_0712 t where levell=4 ) t4
6 union
7 select t5.parent,t5.child,t5.child_qty/t5.parent_qty bili from test_0712 t5 where levell=1 and Child='Z'
8 /
PARENT CHILD QTY
------ ----- ----------
A E 10.8
A Z 3
只看该作者
zhangweicai74
阿财
来自 贵州
精华贴数 3
个人空间
240
技术积分 5712 (232)
社区积分 21774 (59)
注册日期 2007-12-13
论坛徽章:155
#6
使用道具
发表于 2008-7-12 14:50
如果层次不确定的话可能不好写
__________________
NEVER TOO LATE
想吃贵州家乡菜不?进来嘛,老乡!!
http://space.itpub.net/12391917/viewspace-257185
玩玩双节棍(l_l)
想
美丽家乡黄果树瀑布
http://space.itpub.net/12391917/viewspace-244134
只看该作者
lypch
初级会员
精华贴数 0
个人空间
0
技术积分 174 (10622)
社区积分 0 (123093)
注册日期 2004-7-8
论坛徽章:0
#7
使用道具
发表于 2008-7-12 17:00
借用楼上的话,层次多,且不确定的情况下,不好写。
如果下面的例子中,没有A - Z 的话,我可以用一句话写出来,利用Oracel的分析函数就可以实现,但是如果加了A-Z的话,就不行了。
顺便说一下,Level是一个伪列,再表中没有这个字段的,是通过层次查询中弄出来的。这里为了说明简单而标注上了。但再正式的表中是没有这个字段的。
QUOTE:
原帖由
yuanfang830
于 2008-7-12 14:23 发表
SQL> select * from test_0712;
LE PARENT CHILD PA CH
-- ------ ----- -- --
1 A B 1 3
2 B C 2 3
3 C D 5 6
4 D E 1 2
1 A Z 1 3
SQL>
SQL> select t1.parent,t4.child,t1.bili*t2.bili*t3.bili*t4.bili qty from
2 (select t.parent,t.child_qty/t.parent_qty bili from test_0712 t where levell=1 ) t1,
3 (select t.child_qty/t.parent_qty bili from test_0712 t where levell=2 ) t2,
4 (select t.child_qty/t.parent_qty bili from test_0712 t where levell=3 ) t3,
5 (select t.child,t.child_qty/t.parent_qty bili from test_0712 t where levell=4 ) t4
6 union
7 select t5.parent,t5.child,t5.child_qty/t5.parent_qty bili from test_0712 t5 where levell=1 and Child='Z'
8 /
PARENT CHILD QTY
------ ----- ----------
A E 10.8
A Z 3
只看该作者
anoblue
中级会员
精华贴数 1
个人空间
0
技术积分 764 (2473)
社区积分 4 (17144)
注册日期 2003-12-4
论坛徽章:1
#8
使用道具
发表于 2008-7-12 17:35
select parent,child,level1,sys_connect_by_path(childqty/parentqty,'*') rn,
strtonumber(1,substr(trim(sys_connect_by_path(childqty/parentqty,'*')),2))
from tt start with (level1=1) CONNECT BY PRIOR child=parent
strtonumber写的比较差,懒得完善了
create or replace function strtonumber(preadd number,str in varchar2 ) return number
as
n1 number;
n2 number;
strleft varchar2(100);
midadd number;
begin
if str is null or str='' then
return preadd ;
end if;
select decode(substr(str,1,instr(str,'*')-1),null,0,substr(str,1,instr(str,'*')-1)) into n1 from dual;
if n1=0 then
select preadd*str into n1 from dual;
return n1;
end if;
select substr(str,instr(str,'*')+1,decode(sign(instr(str,'*',1,2)-1),1,instr(str,'*',1,2)-instr(str,'*')-1,length(str)-instr(str,'*'))) into n2 from dual;
midadd:=preadd*n1*n2;
if(instr(str,'*',1,2)>1) then
strleft:=substr(str,instr(str,'*',1,2)+1,length(str)-instr(str,'*',1,2));
return strtonumber(midadd,strleft);
else
return midadd;
end if;
end;
__________________
msn:anobluee@hotmail.com找兼职 最好是oracle开发 有时间来做9i Performance tuning|database administration fundamentals
只看该作者
anoblue
中级会员
精华贴数 1
个人空间
0
技术积分 764 (2473)
社区积分 4 (17144)
注册日期 2003-12-4
论坛徽章:1
#9
使用道具
发表于 2008-7-12 17:38
PARENT CHILD LEVEL1 RN RN1
1 A B 1 *3 3
2 B C 2 *3*1.5 4.5
3 C D 3 *3*1.5*1.2 5.4
4 D E 4 *3*1.5*1.2*2 10.8
5 A Z 1 *3 3
__________________
msn:anobluee@hotmail.com找兼职 最好是oracle开发 有时间来做9i Performance tuning|database administration fundamentals
只看该作者
jvkojvko
小马哥
精华贴数 1
个人空间
0
技术积分 5598 (236)
社区积分 44497 (17)
注册日期 2007-9-10
论坛徽章:20
#10
使用道具
发表于 2008-7-12 19:43
mark先
__________________
马无夜草不肥,人无外财不富。
-------------------------------
长期高价出售奥运章
只看该作者
38
1/4
1
2
3
4
››
投票
交易
悬赏
活动
相关内容
ITPUB论坛
≡ 数据库技术 ≡
> Oracle数据库管理
> Oracle开发
> Oracle Developer Suite
> Oracle入门与认证
> Oracle专题深入讨论
> Oracle新技术/11g
> Oracle电子文档
> Oracle Application Server套件
> IBM数据库产品
> MS SQL Server
> Sybase管理与开发
> MySQL及其它开源数据库
> 内存数据库
> 数据仓库与数据挖掘
> 移动及嵌入式数据库
≡ 企业信息化 ≡
> ERP产品与实践
> CRM产品与实践
> HR产品与实践
> 物流
> 供应链
> 供应链建模与仿真
> 物流设备与系统工程
> 企业管理咨询
> 管理协同与办公自动化
> IT服务管理
> 数据中心建设
> ERP二次开发
> Oracle ERP
> EBS相关文档
> PeopleSoft与JDE
> SAP R/3
> SAP Business One开发与快速实施
> SAP财务及CRM
> SAP后勤及HR
> mySAP ERP
> 系统开发及跨应用设置
> SAP相关文档
> 国外其它ERP产品
> 国内ERP产品
≡ 开发技术 ≡
> Java入门与认证版
> Java web开发及框架技术
> Java企业开发
> ASP.NET【已迁移到微软开发技术论坛】
> .Net企业开发与应用【已迁移到微软开发技术论坛】
> WEB程序开发
> WEB 2.0技术
> 动态语言
> 移动与游戏开发
≡ 系统设计与项目管理 ≡
> 系统分析与UML
> 系统分析与UML精华区
> 项目管理
> 项目过程
> 软件测试
> 算法讨论与研究
≡ IBM软件技术园地 ≡
> IBM数据库产品
> Lotus
> Tivoli
> Websphere
> Rational
> 与SOA相关的IBM产品与技术
> IBM软件技术精英协会
> 软件技术精英活动专版
≡ 操作系统与硬件 ≡
> AIX及IBM产品【已迁移到IXPUB】
> HP-UX及HP产品【已迁移到IXPUB】
> Solaris及SUN产品【已迁移到IXPUB】
> Linux及其应用 【已迁移到IXPUB】
> 其它UNIX系统【已迁移到IXPUB】
> windows系统及微软相关产品 【已迁移到IXPUB】
> 存储设备与容灾技术 【已迁移到IXPUB】
> 服务器 【已迁移到IXPUB】
≡ 行业纵向讨论区 ≡
> IT业界评论与展望
> 政府与教育事业
> 中国政府信息主管联盟
> 电信行业
> 金融行业
> 医卫行业
> 制造行业
> 电力行业
> 信息安全与审计
≡ 会员交流 ≡
> IT职业生涯
> 招聘求职商务信息
> 体育世界
> 体育博彩专版
> 旅游,驴友
> 汽车世界
> 外语角
> 数码摄影
> 你的故事我的歌
> 音乐推荐区
> 电子图书与IT文档资料
> 软件交流
> 软件交流精华区
≡ ITPUB产品与服务 ≡
> ITPUB地面活动专版
> BLOG天地
> WIKI世界
> 授权用户区
> 站务管理
≡ 微软开发技术 ≡
> 开发工具和语言
> .NET Framework 相关
> Visual Basic/VB.net
> Visual C#
> Visual C++/vc.net
> Visual Studio
> .NET软件架构与模式
> .NET开发辅助工具及框架
> Web开发
> ASP.NET与AJAX
> Web相关技术讨论(IIS等)
> Silverlight 技术
> 微软企业级产品技术
> SQL Server
> windows server
> SharePoint
> Exchange Server
> Biztalk
> 嵌入式及移动开发
> Windows Embedded 嵌入式技术
> Windows 移动设备
> Office开发
> Microsoft office system
> Office Business Application
> 微软产品用户交流区
> .Net电子书籍&&书籍介绍
> .Net人才交流
技术积分榜
社区积分榜
徽章
电子杂志
会员
团队
统计
邮箱
游乐场
帮助
TOP
CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号
联系我们
法律顾问
控制面板首页
编辑个人资料
积分交易
公众用户组
好友列表
升级个人空间
基本概况
论坛排行
主题排行
发帖排行
积分排行
在线时间
管理团队
管理统计