select depttable0_.dept_id as col_0_0_,
(select count(*) from dept_table depttable1_ where depttable1_.active='1' and depttable1_.parent_dept_code=depttable0_.dept_code and depttable1_.company_code='001') as col_4_0_
from dept_table depttable0_
表dept_table有字段:
DEPT_ID VARCHAR2(50)
DEPT_CODE VARCHAR2(50)
DEPT_NAME VARCHAR2(100)
PARENT_DEPT_CODE VARCHAR2(50)
IN_EMP_CODE VARCHAR2(50)
ACTIVE CHAR(1)
COMPANY_CODE CHAR(3)
EMP_CODE VARCHAR2(50)
UPDATE_DT CHAR(14)
不理解,求大神分析下,跪求
(select count(*) from dept_table depttable1_ where depttable1_.active='1' and depttable1_.parent_dept_code=depttable0_.dept_code and depttable1_.company_code='001') as col_4_0_
from dept_table depttable0_
表dept_table有字段:
DEPT_ID VARCHAR2(50)
DEPT_CODE VARCHAR2(50)
DEPT_NAME VARCHAR2(100)
PARENT_DEPT_CODE VARCHAR2(50)
IN_EMP_CODE VARCHAR2(50)
ACTIVE CHAR(1)
COMPANY_CODE CHAR(3)
EMP_CODE VARCHAR2(50)
UPDATE_DT CHAR(14)
不理解,求大神分析下,跪求
解决方案 »
- htl258(tony)来帮忙!
- 关于触发器 批量删除问题。
- 将SQL 2000的数据库倒入到SQL 2005中
- 为什么我的数据库导出来只有表,就是导不出关系图和视图?
- sqlserver2000 重装以后访问出现:该用户与可信 SQL Server 连接无关联
- SQL 中的命名管道是什么意思?
- 如何实现二进制的移位运算(sql中)
- 请您告诉新入行的新人,此存储过程详细的逻辑和算法,谢谢,来者有分!
- 怎样防止一条纪录被多个用户同时修改
- 关于VC数据库的几个问题
- 有谁知道存储过程可以在查询分析器执行成功,在作业里执行确是失败?
- mysql的一张表中含有32个字段,怎样写存储过程,使得数据可以一次性写入
(select count(*)
from dept_table b
where b.active='1'
and b.parent_dept_code=a.dept_code
and b.company_code='001'
) as col_4_0_
from dept_table a
--求每个部门的符合条件active='1' and company_code='001'的下属部门的个数
DEPT_ID DEPT_CODE DEPT_NAME PARENT_DEPT_CODE ACTIVE COMPANY_CODE
1 00 运营公司 0 1 000
2 00 先声药业 0 1 001
3 0001 OTC部门 00 1 001
是不是执行时,从表a的第一行即dept_id=1开始执行,
此时里面的子查询就变成
select count(*)
from dept_table b
where b.active='1'
and b.parent_dept_code='00' and b.company_code='001'
此时能得到第一行结果;
然后执行dept_id=2这行,
select count(*)
from dept_table b
where b.active='1'
and b.parent_dept_code='00' and b.company_code='001'
此时能得到第二行结果;
然后执行dept_id=3这行,
select count(*)
from dept_table b
where b.active='1'
and b.parent_dept_code='0001' and b.company_code='001'
此时能得到第三行结果;
所以总共有三行结果
请问各位大神是这样分析的吗?我不是太确定