解决方案 »
- sql 去除重复的问题,急,求高人指点...
- 求教组合条件查询.
- 怎样按日期的范围进行查询?
- 在SQL 2005 BAK文件作数据库的完全恢复的时候,有没有办法在恢复的时候,不恢复LOG文件
- 关于SQL SERVER2005排序规则问题
- 为什么MSSQL中NTEXT字段内容却显示的是<long text>?
- 请教一个SQL语句该怎么写?
- 那里有SQL Server 2000的电子书籍下载呢?
- 一个sql语法问题
- sql 相同的字符串判断 不考虑字符串的位置
- 求条sql语句,进来看看吧
- 求一个关于分组的SQL,非常感谢--------------------------------------------------------------
0001 1001 1
0001 1002 10
0001 1004 6
0002 1001 2
0002 1005 4
inventory syscode code name
0001 cp001 成品a
0002 cp002 成品b
1001 cl001 材料a
1002 cl002 材料b
1004 cl003 材料C
1005 cl004 材料d
通过cl001查bom得结果为
父项编码 父项名称 子项编码 子项名称 用量
cp001 成品a cl001 材料a 1
cp002 成品b cl001 材料a 2
通过cl004查bom得结果为
父项编码 父项名称 子项编码 子项名称 用量
cp002 成品b cl004 材料d 4
with bom(fsyscode,csyscode,q)as(
select '0001','1001',1
union all select '0001','1002',10
union all select '0001','1004',6
union all select '0002','1001',2
union all select '0002','1005',4
),inventory(syscode,code,name)as(
select '0001','cp001','成品a'
union all select '0002','cp002','成品b'
union all select '1001','cl001','材料a'
union all select '1002','cl002','材料b'
union all select '1004','cl003','材料C'
union all select '1005','cl004',' 材料d'
)
select c.code,c.name,b.code,b.name,a.q
from bom a,inventory b,inventory c
where b.code='cl004'
and a.csyscode=b.syscode
and a.fsyscode=c.syscode
from bom b
join inventory i1 on b.fsyscode=i1.syscode
join inventory i2 on b.csyscode=i2.syscode
where i2.code='cl004'