Closed drizk1 closed 1 month ago
a slightly more involved example.
mtcars = db_table(db, mtcars_csv)
query = @chain t(mtcars) begin
@group_by cyl
@summarize begin
across(mpg, (mean, minimum, maximum))
num_cars = n()
end
@mutate begin
efficiency = case_when(
mean_mpg >= 25, "High",
mean_mpg >= 15, "Moderate",
"Low" )
end
end;
query2 = @chain t(mtcars) @filter(mpg>20) @mutate(hp = hp *4);
@chain t(query) begin
@left_join(t(query2), cyl, cyl)
@group_by(efficiency)
@summarize(avg_hp = mean(hp))
@mutate(hp3 = avg_hp+1)
@aside @show_query _
@collect
end
2×3 DataFrame
Row │ efficiency avg_hp hp3
│ String Float64 Float64
─────┼──────────────────────────────
1 │ Moderate 440.0 441.0
2 │ High 330.545 331.545
So i accidentally discovered how to do this working on union. I have shown an example below. The issue is that it means that the table name for the joining table (if it is not a query) would need to be written as
"table_name"
or:table_name
as opposed to justtable_name
- this would be a small breaking change, but possibly worth it. Should we go down this road?Edit: I also need to add documentation that you all the joins support the joining arguments ability to be
col - 1
etc. another feature I just realized