ClickHouse / ClickHouse/ClickHouse
`WITH` statement inside subqueries
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
### Company or project name
_No response_
### Question
Hi! I noticed a strange behavior of the `WITH` statement when using subqueries.
For some reason this doesn't work:
```sql
with
A = 2 as selector
select sum(value) from (
select * from test_table where selector
union all
select * from test_table
)
```
While this DOES:
```diff
+select sum(value) from (
with
A = 2 as selector
-select sum(value) from (
select * from test_table where selector
union all
select * from test_table
)
```
I really want to write it the first way because I want to access some stuff in the global scope and it is less convenient to nest the `WITH` statements in my opinion.
So is it a behavior I did not get? If so, is that explained somewhere in the docs?
Thanks in advance 😊
Contributor guide
Assessment
This issue has not been assessed yet.