问个sql合并的问题,希望大家帮助下

wsj1983920 2011-06-22 08:43:36
 select number,c1,c2,c3 from t1 where number in ('xxx')


select number,d1,d2,d3 from t2 where number in ('xxx')


请问查询出来的结果 ,怎么给弄成

number,c1,c2,c3 ,d1,d2,d3

nubmer 在t1,t2 是相同的
...全文
98 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wsj1983920 的回复:]
引用 5 楼 xuexiaodong2009 的回复:
in ('xxx') 是字符串?
我写入多个号码 比如

是('111',‘222’) 还是 ('111,222') ?
搞定了 呵呵 谢谢 我的低级错误 好久不写sql了 郁闷 哈哈
[/Quote]
gx
wsj1983920 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xuexiaodong2009 的回复:]
in ('xxx') 是字符串?
我写入多个号码 比如

是('111',‘222’) 还是 ('111,222') ?
[/Quote]搞定了 呵呵 谢谢 我的低级错误 好久不写sql了 郁闷 哈哈
xuexiaodong2009 2011-06-22
  • 打赏
  • 举报
回复
in ('xxx') 是字符串?
我写入多个号码 比如

是('111',‘222’) 还是 ('111,222') ?
wsj1983920 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xuexiaodong2009 的回复:]
引用 2 楼 hanger1212 的回复:

select t1.number,t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3 from t1 , t2 where t1.number = t2.number and
t1.number in ('xxx')
可以用
[/Quote]
这个在in ('xxx')
条件里 我写入多个号码 比如 111,222 就不会查询出来结果了
xuexiaodong2009 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hanger1212 的回复:]

select t1.number,t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3 from t1 , t2 where t1.number = t2.number and
t1.number in ('xxx')
[/Quote]可以用
hanger1212 2011-06-22
  • 打赏
  • 举报
回复
select t1.number,t1.c1,t1.c2,t1.c3,t2.c1,t2.c2,t2.c3 from t1 , t2 where t1.number = t2.number and
t1.number in ('xxx')
AcHerat 2011-06-22
  • 打赏
  • 举报
回复

select number,max(c1)c1,max(c2)c2,max(c3)c3,max(d1)d1,max(d2)d2,max(d3)d3
from(
select number,c1,c2,c3,null as d1,null as d2,null as d3 from t1 where number in ('xxx')
union all
select number,null,null,null,d1,d2,d3 from t2 where number in ('xxx')
)t
group by number
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 fredrickhu 的回复:]
引用 6 楼 wsj1983920 的回复:
引用 5 楼 xuexiaodong2009 的回复:
in ('xxx') 是字符串?
我写入多个号码 比如

是('111',‘222’) 还是 ('111,222') ?
搞定了 呵呵 谢谢 我的低级错误 好久不写sql了 郁闷 哈哈

gx
[/Quote]

27,580

社区成员

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

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