日期:2014-05-17  浏览次数:20679 次

两张表的连接
有一张表,Small, Small表中每一个advertiserId对应很多账号,账号放在表 account中。
两张表连接以后就是下边的表Big.
SQL怎么写?  


--table Small
AdvertiserId  GroupId
1                0
2                0
3                0

--table Big
AdvertiserId  GroupId  Account
1             0        101
1             0        102
1             0        103
2             0        201
2             0        987
2             0        9792
3             0        213
3             0        234
3             0        917


------解决方案--------------------

--Small
if object_id('Small','u') is not null
drop table Small
go
create table Small
(
AdvertiserId int,
GroupID int
)
go
insert into Small values
(1,0),
(2,0),
(3,0)

--Account
if object_id('Account','u') is not null
drop table Account
go
create table Account
(
AdvertiserId int,
AccountId int
)
go
insert into Account values
(1,101),