日期:2014-05-18  浏览次数:20435 次

求plsql语句 复杂模型
tb1
tb1code   primary   key   --编号唯一  
Name  

tb2
tb2code   primary   key   --编号唯一
tb1code  
name


tb3
tb3code   primary   key   --编号唯一
tb2code  
issue     其次     int         (最大)
A
B
C

其中   tb1是一个大分类
tb2是tb1的小分类
tb3是具体到小分类的数据

现在  

按tb1大分类分组   然后   issue最大的元组

主要是   tb3code   还有后面的数据,
不能俺   ABC分组的。



------解决方案--------------------
我不懂 帮顶了
------解决方案--------------------
没看明白。这道题确实复杂!
------解决方案--------------------
没看明白~!但帮顶。。
------解决方案--------------------
看不明白楼主给我条件。。。。
------解决方案--------------------
select tb1.tb1code,tb1.name,tb3.tb3code,tb3.qty,tb3.字段1
from tb1,tb3,
(select tb1code,max(qty) as qty
from tb3 ,tb2
where tb3.tb2code = tb2.tb2code
group by tb1code) tbTmp
where tb1.tb1code = tbTmp.tb1code and tb3.qty = tbTmp.qty
------解决方案--------------------
那我理解的有問題,稍作修改。

你測試下得到的結果是否正確。


Select
A.tb1code,
A.name,
C.tb3code,
C.qty,
C.字段1,
C.字段2,
C.字段3
From
tb1 A
Inner Join
tb2 B
On A.tb1code = B.tb1code
Inner Join
tb3 C
On B.tb2code = C.tb2code
Inner Join
(Select Max(qty) As qty, tb2.tb1code From tb2 Inner Join tb3 On tb2.tb2code = tb3.tb2code Group By tb2.tb1code) D
On B.tb1code = D.tb1code And C.qty = D.qty