select a.rjid from RPT_CATEGORY_SCHOOL as a
where a.nd=(select res from xt_cssz where rjid=a.rjid and mc='nd' and lx='Init')
group by rjid在子查询中 有个 rjid=a.rjid 我不太明白 这个a.rjid 是取的a表的 哪一行 作为条件一般情况 都是将 条件设置为变量 比如select a.rjid from RPT_CATEGORY_SCHOOL as a where a.nd=2011 group by rjid求高手解释下
where a.nd=(select res from xt_cssz where rjid=a.rjid and mc='nd' and lx='Init')
group by rjid在子查询中 有个 rjid=a.rjid 我不太明白 这个a.rjid 是取的a表的 哪一行 作为条件一般情况 都是将 条件设置为变量 比如select a.rjid from RPT_CATEGORY_SCHOOL as a where a.nd=2011 group by rjid求高手解释下
where a.nd= b.res and a.rjid=a.rjid and mc='nd' and lx='Init'
group by rjid
主查询正在查的那一条记录.
不过你这条语句有点儿毛病,如果子查询查到两条记录,就会出错,还有,你又没做统计,要group 干吗?
这样可能更好:
select distinct rjid from RPT_CATEGORY_SCHOOL as a
where exists(select 1 from xt_cssz where res=a.nd and rjid=a.rjid and mc='nd' and lx='Init')
子查询根据 a.rjid 与子查询中所查表的 rjid对照,查出结果集或是否存在信息.
如果 匹配成功即返回 主查询的记录