34,593
社区成员
发帖
与我相关
我的任务
分享
select * from A cross join B
SELECT * FROM
(SELECT dlbh FROM t_spda) a
CROSS APPLY
(SELECT xslb, lbzk FROM t_xslb) b
create table t_spda(dlbh INT)
create table t_xslb(xslb int,lbzk float)
insert into t_spda
select 5000 union all
select 5001 union all
select 5002
insert into t_xslb
select 1,0.7 union all
select 2,0.8 union all
select 3,0.9
select * from t_spda,t_xslb order by dlbh
drop table t_spda,t_xslb
/*
5000 1 0.7
5000 2 0.8
5000 3 0.9
5001 1 0.7
5001 2 0.8
5001 3 0.9
5002 1 0.7
5002 2 0.8
5002 3 0.9
*/
select * from tablea,tableb
create table a(id int,ic int)
insert into a
select 1,5000 union all
select 2,5001
go
create table b(ig decimal(6,2))
insert into b
select 6.1 union all
select 6.11
go
--1
select *
from a,b
--2
select *
from a cross join b
drop table a,b
/*
id ic ig
----------- ----------- ---------------------------------------
1 5000 6.10
2 5001 6.10
1 5000 6.11
2 5001 6.11
(4 行受影响)
id ic ig
----------- ----------- ---------------------------------------
1 5000 6.10
2 5001 6.10
1 5000 6.11
2 5001 6.11
(4 行受影响)
use tempdb;
/*
create table t_spda
(
dlbh int not null
);
insert into t_spda(dlbh) values(5000),(5001),(5002);
create table t_xslb
(
xslb int not null,
lbzk decimal(10,1) not null
);
insert into t_xslb(xslb,lbzk) values(1,0.7),(2,0.8),(3,0.9);
*/
select *
from t_spda as t1
cross join t_xslb as t2
order by t1.dlbh;