不知道!请教

owenfan521 2003-10-16 07:19:01
有三个表:
a表
tagindex tagvalue time
1 3 11:30
2 7 11:30
1 4 11:40
2 8 11:40
b表
tagname tagindex
kk 1
ss 2
c表
tagname tagdescription
kk 液位
ss 压力
请问如何用一个查询语句得出下面的结果
tagdescription tagvalue time
液位 3 11:30
压力 7 11:30
液位 4 11:40
压力 8 11:40


...全文
51 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-10-16
  • 打赏
  • 举报
回复
select (select tagdescription from C表 where tagname=(select tagname from b表 where tagindex=a表.tagindex)),tagvalue,[time] from a表
pengdali 2003-10-16
  • 打赏
  • 举报
回复
select (select tagdescription from C表 where tagname=(select tagname from b表 where tagindex=a表.tagindex)),a.tagvalue,a.[time] from a表
txlicenhe 2003-10-16
  • 打赏
  • 举报
回复

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.tagname

tagdescription tagvalue time
-------------- ----------- -----
液位 3 11:30
压力 7 11:30
液位 4 11:40
压力 8 11:40

(所影响的行数为 4 行)

owenfan521 2003-10-16
  • 打赏
  • 举报
回复
大侠,我做的VB控件生成的语句就是这样的,
select c.description,a.tagvalue,a.time
from a表
inner join b表 on a.tagindex=b.tagindex
inner join b.tagname=c.tagname
为什么得不到这个结果呢?
txlicenhe 2003-10-16
  • 打赏
  • 举报
回复
Select c.tagdescription,a.tagvalue,a.time
from a表
join b表 on a.tagindex = b.tagindex
join c表 on b.tagname = c.tagname

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧