日期:2014-05-16  浏览次数:20640 次

SQL语句问题,从来没有遇到过
SELECT   count(distinct   UP_ID)
from   rel_table
where   ((DOWN_TYPE   =   'PH ')   OR   (DOWN_TYPE   =   'UI '))AND     (UP_TYPE   =   'LH ')AND   UP_ID   IN
(select   LH_ID
from   rel_lhfunc_table
where   ID
in
(
    select   ID
    from   function_table
    where   name= 'A1 '
    )
);

其中第3行的UP_ID和第4行的LH_ID是完全一样的同一个东西。
1、我能不能用这样的语句完成嵌套啊?因为从前用的都是名字一样的,现在却不同。2、我试过了和预想的不一样,请问是我逻辑有问题,还是语句有问题啊?


------解决方案--------------------
听lZ意思,我觉得可以写成这样:

SELECT count(distinct UP_ID)
from rel_table a,rel_lhfunc_table b
where ((a.DOWN_TYPE = 'PH ') OR (a.DOWN_TYPE = 'UI '))
AND (a.UP_TYPE = 'LH ') AND a.UP_ID =b.LH_ID
AND b.LH_ID in(select ID from function_table where name= 'A1 ')

不知道对不对.