一个简单的查询 在线

zhouzhijian888 2008-11-01 06:23:11
我有3个表 数据的行数 都一样 但是列名不一样
我想把 3个表的结果 都组织到一起 组成个新的结果集
需要怎么做
...全文
115 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wujumao 2008-11-02
  • 打赏
  • 举报
回复
保证每一个子结果集的字段名,字段类型 一致。
lihuanmei 2008-11-01
  • 打赏
  • 举报
回复
select *,id=identity(int,1,1) into #1 from a
select *,id=identity(int,1,1) into #2 from b
select *,id=identity(int,1,1) into #3 from c
select 名字=#1.name,年龄=#2.age,地址=#3.dress
into #
from #1 inner join #2 on #1.id=#2.id inner join #3 on #1.id=#3.id
order by #1.id
select * from #
drop table #1
drop table #2
drop table #3
drop table #
lihuanmei 2008-11-01
  • 打赏
  • 举报
回复
select *,id=identity(int,1,1) into #1 from a
select *,id=identity(int,1,1) into #2 from b
select *,id=identity(int,1,1) into #3 from c
select name,age,dress
into #
from #1 inner join #2 on #1.id=#2.id inner join #3 on #1.id=#3.id
order by #1.id
ljhcy99 2008-11-01
  • 打赏
  • 举报
回复

假设 ta 有 aa1 ,bb1字段, tb 有 aa2 ,bb2字段, tc 有 aa3 ,bb3字段,


select ta.aa1 as A,ta.bb1 As B from ta
union all
select tb.aa2 as A,tb.bb2 As B from tb
union all
select tc.aa3 as A,tc.bb3 As B from tc


保证每一个子结果集的字段名,字段类型 一致。
lihuanmei 2008-11-01
  • 打赏
  • 举报
回复
我想应该对每一个表加标识符,例如ID=identity()
-晴天 2008-11-01
  • 打赏
  • 举报
回复
create table tb1(id int,cola int,othercol varchar(10))
insert into tb1 select 4,7,'fasd'
insert into tb1 select 7,5,'fwe'
create table tb2(id int,colb varchar(10),othercol varchar(10))
insert into tb2 select 3,'as','vwe'
insert into tb2 select 5,'mnivw','fwe'
--设两表都由id列排序:
select t1.cola,t2.colb from
(select cola,(select count(*) from tb1 where id<=a.id) as id0 from tb1 a)t1 inner join
(select colb,(select count(*) from tb2 where id<=b.id) as id0 from tb2 b)t2
on t1.id0=t2.id0
go
drop table tb1,tb2
/*
cola colb
----------- ----------
7 as
5 mnivw

(2 行受影响)
*/
-晴天 2008-11-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qianjin036a 的回复:]
可以,但得有个排列依据.
[/Quote]
列几条真实的数据看看,注意有没有ID列.
zhouzhijian888 2008-11-01
  • 打赏
  • 举报
回复
没有满意的 union 不能用!~~~
zhouzhijian888 2008-11-01
  • 打赏
  • 举报
回复
不是 是把 数据 并排起来就行 不合并
例如
a 表 b表 c表
name age dress
1 3 as
2 5 dssf
3 6 dasdf
我只要表中指定的列 其他列 我不要 数据的行数是相等的
zhouzhijian888 2008-11-01
  • 打赏
  • 举报
回复
包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式。



-晴天 2008-11-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhouzhijian888 的回复:]
我试试 可以的话 我就结贴
[/Quote]
听你的意思是把数据排到同一行里?
zhouzhijian888 2008-11-01
  • 打赏
  • 举报
回复
我试试 可以的话 我就结贴
-晴天 2008-11-01
  • 打赏
  • 举报
回复
可以,但得有个排列依据.
jiangshun 2008-11-01
  • 打赏
  • 举报
回复
新建一个表,然后分别把着三个表中的数据导进去就可以了
水族杰纶 2008-11-01
  • 打赏
  • 举报
回复
select * from ta
union all
select * from tb
union all
select * from tc
版本:presto-server-0.214.tar软件版本 presto-cli-0.214-executableCentOS71、presto的起因 hadoop ---hdfs----MR(java)-----hivehive底层原理用MR,速度比较慢,公司hadoop集群主要集中于晚上到凌晨,平日工作时间负载不是很高。但在工作时间内,公司业务人员有实时查询的需求,现在主要借助于hive提供业务人员的查询。hive是基于MR类的SQL查询工具,他会输入的查询SQL解析为MapReduce,能极大的降低使用大数据门槛,让一般的业务人员可以直接准对大数据进行查询,但是有一个利弊,它的查询基于MR,会让人等待比较着急,等待的时间可能是几个小时或者一天。 spark基于内存提高改良的hive,sql,现在factbook在hive上面开发一套利器,准对hive可以通过sql语句快速查询,presto。2、Facebook为何开发Presto  Facebook的2011的数据仓库存储在少量大型hadoopfs集群,Hive是FaceBook在几年前专门为Hadoop打造的一款数据仓库工具,在以前,facebook的科学家和分析师一直靠hive进行数据分析.但hive使用MR作为底层计算框架,是专为批处理设计的,但是随着数据的不断增多,使用hive进行一个简单的数据查询可能要花费分钟或者几个小时,显然不能满足查询需求,FaceBooke也调研了其他比hive更快的工具,但是他们需要在功能有限的条件下做简单操作,以至于无法操作Facebook庞大的数据要求。2012年开始研究自己的框架--presto,每日可以超过1pb查询,而且速度比较快,faceBook声称Presto的性能比hive要好上10倍或者100倍,presto和hive都是facebook开发的 Presto是一个开源的分布式SQL查询引擎,适用于交互式查询,数据量支持GB到PB字节。Presto的设计和编写完全是为了解决Facebook这样规模的商业数据仓库交互式分析和处理速度的问题Presto可以做什么 Presto支持在线数据查询,包括Hive kafka Cassandra关系数据库以及专门数据存储,一条Presto查询可以将多个数据源进行合并,可以跨越整个组织进行分析。Presto以分析师的需求作为目标,他们期望相应速度小于1秒到几分钟,Presto要么在使用速度的快的昂贵的商业方案,提高内存,要么是消耗大量的硬件进行快速查询。(128G 64G)本套课程教给如何在企业环境中使用Presto技术。

34,590

社区成员

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

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