SQL Explorer
Demo Environment
This environment resets nightly. Any data or connections you add are public.
SQL Explorer
New Query
Playground
Connections
Logs
Favorites
Playground Query
near "as": syntax error
Title
default
tq
base
history_1390634-1970-01-01-MAX_1.db
RMS
179146-Activity_2024-07-12_07-47_101208779_1.db
job_summary_1.db
vehicles_1.db
job_skills_1.db
IMDbMovies-Clean_1.db
sqlite-sakila.db
northwind.db
transactions_1.db
organizations-100000_1.db
maestro-v3.0.0_1.db
job_postings_1.db
Connection
Description
SQL
with RECURSIVE r as ( SELECT 0 as len , cidr '0.0.0.0/0' as parent , child.child as child , case when child.child = (cidr '0.0.0.0/1') then 7000 else 3000 end :: float as views , case when child.child = (cidr '0.0.0.0/1') then 230 else 20 end :: float as sales , floor(random() * 10) / 10 as next_split , floor(random() * 10) / 10 as next_sales_split , row_number() over () as row from ( select set_masklen('0.0.0.0/0', 1) as child union select set_masklen(broadcast(set_masklen('0.0.0.0/0', 1)) + 1, 1)::cidr ) child UNION SELECT len + 1 as len , r.child :: cidr as parent , cs.child :: cidr as child , round(case when row_number() over (partition by r.child order by cs) = 1 then r.views * r.next_split else r.views * (1 - r.next_split) end) as views , round(case when row_number() over (partition by r.child order by cs) = 1 then r.sales * r.next_sales_split else r.sales * (1 - r.next_sales_split) end) as sales , floor(random() * (case when len >= 2 then 5 else 10 end)) / (case when len >= 2 then 5 else 10 end) as next_split , floor(random() * (case when len >= 2 then 5 else 10 end)) / (case when len >= 2 then 5 else 10 end) as next_sales_split , row_number() over (partition by r.child order by cs.child) as row from r join lateral ( select set_masklen(r.child, masklen(r.child) + 1) as child union select set_masklen(broadcast(set_masklen(r.child, masklen(r.child) + 1)) + 1, masklen(r.child) +1)::cidr ) cs on true WHERE len < 5 ) -- select * from r , s as ( SELECT len, parent, array_agg(child) as children , sum(views) as views , sum(sales) as sales -- '"' || parent || '" -- ' || '"' || child || '"' from r group by len, parent order by len, parent ) select * from r
Save & Run
Save Only
Download...
CSV
JSON
Show Schema
Hide Schema
Format
SQL Assistant
Assistant prompt
"Ask Assistant" to try and automatically fix the issue. The assistant is already aware of error messages & context.
Select All
(?)
Search tables
Ask Assistant
Loading...
Avg. execution: 7.925ms. Query created by admin on 2024-07-05.
History