两个表的联合查询问题,急等

phoenix2xp 2004-08-13 11:33:03
两个表,表1有字段:col1、col2、col3,表2有字段:code、value。其中表1中每个字段的值都可以在表2value字段中找到对应值,另外还有几个表一起联合查询

现在我希望查询结果中把表1中col1、col2、col3字段的值都用表2中对应的code代替,请问该如何实现呢?
...全文
191 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveSQL 2004-08-13
  • 打赏
  • 举报
回复
select
(select top 1 code from table2 where value=a.col1) as col1,
(select top 1 code from table2 where value=a.col2) as col2,
(select top 1 code from table2 where value=a.col3) as col3
from table1 a
victorycyz 2004-08-13
  • 打赏
  • 举报
回复

select c1=(select [value] from table2 where code=a.col1),
c2=(select [value] from table2 where code=a.col2),
c3=(select [value] from table2 where code=a.col3)
from table1

pbsql 2004-08-13
  • 打赏
  • 举报
回复
select (select code from t2 where value=t1.col1) code1,
(select code from t2 where value=t1.col2) code2,
(select code from t2 where value=t1.col3) code3
from t1
yesterday2000 2004-08-13
  • 打赏
  • 举报
回复
select b.code from 表1 a,表2 b where a.col1=b.value or a.col2=b.value or a.col3=b.value
phoenix2xp 2004-08-13
  • 打赏
  • 举报
回复
发现LoveSQL(GG)的才能得到我要的结果,才给了你3分,实在不好意思;)
phoenix2xp 2004-08-13
  • 打赏
  • 举报
回复
可以了!

多谢各位:)

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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