计数离开属性分层语言

时间:2018-05-25 02:52:44

标签: oracle plsql oracle11g

我有两张表如下:

==============================          ==============================                                  
Directories                             Items
==============================          ==============================
ID    |Name         |Parent             ID    |Name         |Directory
1     |All          |null               1     |Simpson      |6
2     |Movies       |1                  2     |Avatar       |5
3     |Clips        |1                  3     |Tom&Jerry    |6
4     |Games        |1                  4     |CoD          |7
5     |Action       |2                  5     |CS           |7
6     |Cartoon      |2                  6     |NFS          |8
7     |Shooter      |4                  7     |Halo         |7
8     |Racing       |4                  8     |F4           |8
9     |Music        |3                  9     |Thriller     |9
                                        10    |Beat it      |3

我想获得结果,以查看目录中每个目录中有多少项目 上面的表格,我只能指望一个特定的目录,但是对所有类别使用一个查询都不成功,所以我该怎么做,谢谢。

================================
Result
================================
ID    |Name         |Items Count
1     |All          |10
2     |Movies       |3
3     |Clips        |2
4     |Games        |5
5     |Action       |1
6     |Cartoon      |2
7     |Shooter      |3
8     |Racing       |2
9     |Music        |1

1 个答案:

答案 0 :(得分:0)

如果您正在寻找所有后代,请使用connect by