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

这样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 '
    )
);

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


------解决方案--------------------
SELECT count(distinct UP_ID)
from rel_table a inner join rel_lhfunc_table b on a.UP_ID=b.LH_ID inner join function_table c on b.ID=c.ID and c.name= 'A1 '
where (DOWN_TYPE = 'PH ' OR DOWN_TYPE = 'UI ') AND UP_TYPE = 'LH ';

看看这样写如何。