如何实现这样的查询结果
表A:
列1
a
b
c
表B:
列1 列2
a 1
a 2
a 3
结果:
列1 列2
a 1
a 2
a 3
b 1
b 2
b 3
c 1
c 2
c 3
求大仙解一下!
[解决办法]
--?
select a.列1,
b.列2
from 表A a ,表B b
[解决办法]
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-12-04 17:34:16
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
--Dec 28 2012 20:23:12
--Copyright (c) Microsoft Corporation
--Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[A]
if object_id('[A]') is not null drop table [A]
go
create table [A]([列1] varchar(1))
insert [A]
select 'a' union all
select 'b' union all
select 'c'
--> 测试数据:[B]
if object_id('[B]') is not null drop table [B]
go
create table [B]([列1] varchar(1),[列2] int)
insert [B]
select 'a',1 union all
select 'a',2 union all
select 'a',3
--------------开始查询--------------------------
select a.列1,b.列2 from [A] CROSS JOIN [b]
ORDER BY a.列1
----------------结果----------------------------
/*
列1 列2
---- -----------
a 1
a 2
a 3
b 1
b 2
b 3
c 1
c 2
c 3
*/