高分,求解决SQL有关问题
高分,求解决SQL问题!
比如:select name from t1和select id from t2
id name
1 张三
2 李四
3 王五
把两条查询出来的数据合并起来显示。
------解决方案--------------------
这个是不是这样可以,你试试:
比如:select name from t1和select id from t2
id name
1 张三
2 李四
3 王五
把两条查询出来的数据合并起来显示。
------解决方案--------------------
这个是不是这样可以,你试试:
--drop table t1,t2
create table t1(name varchar(10))
insert into t1
select '张三' union all
select '李四' union all
select '王五'
create table t2(id int)
insert into t2
select 1 union all
select 2 union all
select 3
go
select t2.id,t1.name
from
(
select Name,
ROW_NUMBER() over(order by getdate()) rownum
from t1
)t1
inner join
(
select id,
ROW_NUMBER() over(order by getdate()) rownum
from t2
)t2
on t1.rownum = t2.rownum
/*
id name
1 张三
2 李四
3 王五
*/