SQL集合运算符语法优化

Viewed 100

感觉集合运算符的语法很奇怪, 不加 where 条件时, 只有 union 可以接受换行写下一个 select, 其他 intersect, except, minus 都会报错, 不能换行, 一定要关键字后接 select

加 where 后, intersect 和 except 就可以换行写下一个 select, 但是 minus 无论换行还是不换行都会报错

不加 where

--只有union可以接受这个语法, intersect/except/minus报错
select * from table1
union
select * from table2

--intersect/except/minus的正确执行语法
select * from table1
intersect/except/minus select * from table2

加 where

--此时intersect和except就可以接受换行, 可以正确执行
--但是minus无论换不换行都报错
select * from table1 where datadate = 20240101
union/intersect/except
select * from table2 where datadate = 20240101

doris: 2.1.5
目前doris只实现了UNION, 还没有 INTERSECT 和 EXCEPT(MINUS) 的实现
具体可参考:
https://www.alibabacloud.com/help/zh/maxcompute/user-guide/intersect-union-except-and-minus

2 Answers

已经实现了,专项测试中, 后续会补齐文档

感觉集合运算符的语法很奇怪, 不加 where 条件时, 只有 union 可以接受换行写下一个 select, 其他 intersect, except, minus 都会报错, 不能换行, 一定要关键字后接 select

加 where 后, intersect 和 except 就可以换行写下一个 select, 但是 minus 无论换行还是不换行都会报错