SAP HANA SQL语句UNION 和 UNION ALL的用法
来源:互联网 发布:windows下vim编辑器 编辑:程序博客网 时间:2024/06/06 08:52
SAP HANA SQL语句UNION 和 UNION ALL的用法
UNION ALL--不合并重复行
Selects all records from all selectstatements. Duplicates are not removed
UNION [DISTINCT] --合并重复行UNION 和 UNION DISTINCT功能相同
Selects all unique records from all selectstatements by removing duplicates found from different select statements. UNION has the same function as UNION DISTINCT.
合并重复行
select * from A union select * from B
不合并重复行 select * from A union all select * from B
按某个字段排序 --合并重复行
select * from ( select * from A union select * from B) AS T order by 字段名
不合并重复行
select * from ( select * from A union all select * from B) AS T order by 字段名
create column table tunion_1( id int primary key, customer varchar(5), year int, product varchar(5), sales int );
create column table tunion_2 ( id int primary key, customer varchar(5), year int, product varchar(5), sales int );
insert into tunion_1values(1, 'C1', 2009, 'P1', 100);
insert into tunion_1values(2, 'C1', 2009, 'P2', 200);
insert into tunion_1values(3, 'C1', 2010, 'P1', 50);
insert into tunion_1values(4, 'C1', 2010, 'P2', 150);
insert into tunion_1values(5, 'C2', 2009, 'P1', 200);
insert into tunion_1values(6, 'C2', 2009, 'P2', 300);
insert into tunion_1values(7, 'C2', 2010, 'P1', 100);
insert into tunion_1values(8, 'C2', 2010, 'P2', 150);
insert into tunion_2 values(1, 'C1', 2011, 'P1', 100);
insert into tunion_2 values(2, 'C1', 2011, 'P2', 200);
insert into tunion_2 values(3, 'C1', 2011, 'P1', 50);
insert into tunion_2 values(4, 'C1', 2011, 'P2', 150);
insert into tunion_2 values(5, 'C2', 2011, 'P1', 200);
insert into tunion_2 values(6, 'C2', 2011, 'P2', 300);
insert into tunion_2 values(7, 'C2', 2011, 'P1', 100);
insert into tunion_2 values(8, 'C2', 2011, 'P2', 150);
insert into tunion_2 values(9, 'C1', 2011, 'P1', 100);
select count(1) from (select customer,year,product,sales from tunion_1 union select customer,year,product,sales from tunion_2) 结果--->> 16
select count(1) from (select customer,year,product,sales from tunion_1 UNION DISTINCT select customer,year,product,sales from tunion_2) 结果 --->> 16
select count(1) from (select customer,year,product,sales from tunion_1 union all select customer,year,product,sales from tunion_2) 结果—>>17
select * from (select customer,year,product,sales from tunion_1 union all select customer,year,product,sales from tunion_2) order by customer
select * from (select customer,year,product,sales from tunion_1 union select customer,year,product,sales from tunion_2) order by customer
- SAP HANA SQL语句UNION 和 UNION ALL的用法
- SAP HANA SQL语句UNION 和 UNION ALL的用法
- SAP HANA关于UNION和UNION ALL
- sql语句查询结果合并union 和union all用法
- sql语句查询结果合并union 和union all用法
- sql语句查询结果合并union 和union all用法
- sql语句查询结果合并union 和union all用法
- 合并union 和union all用法-sql语句查询结果
- SQL语句UNION与UNION ALL的用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- SQL Union和SQL Union All用法
- 设计模式-目录
- Java遍历磁盘文件的时候出现空指针异常(NullPointException)
- 使用Intel® 82599 VF 功能,在虚拟机里运行 (f-stack)nginx 代理功能多进程总结
- 浏览器主页被篡改,劫持
- ztree树的异步加载async
- SAP HANA SQL语句UNION 和 UNION ALL的用法
- Linux自动磁盘挂载工具home目录版
- VC++6.0操作excel2007文件封装类CExcelServer(OLE/COM)
- JS实现判断滚动条滚到页面底部并执行事件的方法
- Command /usr/bin/codesign failed with exit code 1
- poj 3624 Balanced Lineup
- anr用户无响应问题的解决
- SAP HANA中的触发器(Trigger)
- git常用的指令