这样的SQL语句怎么写?

hcyzg 2008-05-17 04:49:02
table1:
a b e
a c e
a d e

table2:
a b f
a c f

希望得到的结果是:

a b e f
a c e f
a d e f
...全文
78 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ojuju10 2008-05-17
  • 打赏
  • 举报
回复
[Quote=引用楼主 hcyzg 的帖子:]
table1:
a b e
a c e
a d e

table2:
a b f
a c f

希望得到的结果是:

a b e f
a c e f
a d e f
[/Quote]

select a.*,c4=isnull(b.c4,'') from table1 a left join table b
on a.c1=b.c1 and a.c2=b.c2
hcyzg 2008-05-17
  • 打赏
  • 举报
回复
f 是不定值的情况
比如当 f为空的时候
table2就变成:
a b
a c
此时我想得到的结果就变成是:
a b e
a c e
a d e


所以,大家提供的办法对我来说都不可行啊~
是我没表达清楚,Sorry~
期待高手来解答~
hcyzg 2008-05-17
  • 打赏
  • 举报
回复
f 是不定值的情况
比如当 f为空的时候
table2就变成:
a b
a c
此时我想得到的结果就变成是:
a b e
a c e
a d e


所以,大家提供的办法对我来说都不可行啊~
是我没表达清楚,Sorry~
期待高手来解答~
帅虫哥 2008-05-17
  • 打赏
  • 举报
回复
用连接就可以了
假设table1中
a b e 的列名 为 a1 b1 e1
假设table2中
a b f 的列名为 a1 b1 f1
代码
select table1.a1 ,table1.b1 ,table1.e1 , table2.f1 from table1 ,table2 where table1.a1=table2.a1 and table1.b1 = table2.b1
jlwei888 2008-05-17
  • 打赏
  • 举报
回复
select t1.column1,t1.column2,t1.column3,t2.column3
from talbe t1 ,table2 t2
where t1.column1=t2.column1 and t1.column2=t2.column2
Limpire 2008-05-17
  • 打赏
  • 举报
回复
select *, 'f' from table1

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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