Cross Join 交叉结合三个表以上怎么写

andrew064 2012-01-09 02:43:46
请给几个实例, 谢谢

另外,cross join与left join 同时使用又怎么写呢?同样是多个表,
...全文
242 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
苦苦的潜行者 2012-01-09
  • 打赏
  • 举报
回复
select * from a,b,c

tiger_dxc 2012-01-09
  • 打赏
  • 举报
回复

declare @a table (id int)
insert into @a
select 1 union all
select 2 union all
select 3

declare @b table (id int)
insert into @b
select 2 union all
select 3 union all
select 4

declare @c table (id int)
insert into @c
select 1 union all
select 2 union all
select 4

select * from @a a
left join @b b on a.id=b.id
cross join @c c

andrew064 2012-01-09
  • 打赏
  • 举报
回复
select * from @a a
left join @b b on a.id=b.id
cross join @c c

可以这样子吗?
select * from @a a 
left join @b b on a.id=b.id and a.其它字段='xxx'
cross join @c c
where c.其它字段='yyyyy'
勿勿 2012-01-09
  • 打赏
  • 举报
回复
楼上的例子很实际。
叶子 2012-01-09
  • 打赏
  • 举报
回复

declare @a table (id int)
insert into @a
select 1 union all
select 2 union all
select 3

declare @b table (id int)
insert into @b
select 2 union all
select 3 union all
select 4

declare @c table (id int)
insert into @c
select 1 union all
select 2 union all
select 4

select * from @a a
left join @b b on a.id=b.id
cross join @c c

/*
id id id
----------- ----------- -----------
1 NULL 1
1 NULL 2
1 NULL 4
2 2 1
2 2 2
2 2 4
3 3 1
3 3 2
3 3 4
*/
叶子 2012-01-09
  • 打赏
  • 举报
回复

declare @a table (id int)
insert into @a
select 1 union all
select 2 union all
select 3

declare @b table (id int)
insert into @b
select 2 union all
select 3 union all
select 4

declare @c table (id int)
insert into @c
select 1 union all
select 2 union all
select 4

select * from @a a
left join @b b on a.id=b.id
left join @c c on a.id=c.id
/*
id id id
----------- ----------- -----------
1 NULL 1
2 2 2
3 3 NULL
*/

select * from @a a
cross join @b b cross join @c c
/*
id id id
----------- ----------- -----------
1 2 1
1 2 2
1 2 4
2 2 1
2 2 2
2 2 4
3 2 1
3 2 2
3 2 4
1 3 1
1 3 2
1 3 4
2 3 1
2 3 2
2 3 4
3 3 1
3 3 2
3 3 4
1 4 1
1 4 2
1 4 4
2 4 1
2 4 2
2 4 4
3 4 1
3 4 2
3 4 4
*/

34,838

社区成员

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

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