Select c.tagdescription,a.tagvalue,a.time
from a表
join b表 on a.tagindex = b.tagindex
join c表 on b.tagname = c.tagname

解决方案 »

  1.   

    大侠,我做的VB控件生成的语句就是这样的,
     select c.description,a.tagvalue,a.time 
    from a表 
    inner join b表 on a.tagindex=b.tagindex
    inner join b.tagname=c.tagname
     为什么得不到这个结果呢?
      

  2.   


    Create table a表(tagindex int,tagvalue int,time char(5))
    insert a表 select 1,3,'11:30'
    union all select 2,7,'11:30'
    union all select 1,4,'11:40'
    union all select 2,8,'11:40'Create table b表(tagname char(2),tagindex int)
    insert b表 select 'kk',1
    union all select 'ss',2
    Create table c表(tagname char(2),tagdescription varchar(10))
    insert c表 select 'kk','液位'
    union all select 'ss','压力'Select c.tagdescription,a.tagvalue,a.time
    from a表 a
    join b表 b on a.tagindex = b.tagindex
    join c表 c on b.tagname = c.tagname
    Select c.tagdescription,a.tagvalue,a.time
    from a表 a
    join b表 b on a.tagindex = b.tagindex
    join c表 c on b.tagname = c.tagnametagdescription tagvalue    time  
    -------------- ----------- ----- 
    液位             3           11:30
    压力             7           11:30
    液位             4           11:40
    压力             8           11:40(所影响的行数为 4 行)
      

  3.   

    select (select tagdescription from C表 where tagname=(select tagname from b表 where tagindex=a表.tagindex)),a.tagvalue,a.[time] from a表
      

  4.   

    select (select tagdescription from C表 where tagname=(select tagname from b表 where tagindex=a表.tagindex)),tagvalue,[time] from a表