首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

这样SQL语句有关问题,从来没有遇到过!

2012-03-19 
这样SQL语句问题,从来没有遇到过!!!!SELECTcount(distinctUP_ID)fromrel_tablewhere((DOWN_TYPEPH )OR(DO

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

看看这样写如何。


热点排行