-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98fb7e6
commit 61df6bf
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
I have two tables: | ||
|
||
tableA looks like this: | ||
|
||
id | number | ||
1 | 100 | ||
2 | 120 | ||
3 | 300 | ||
|
||
table B looks like this: | ||
number | longitude | ||
100 | -41.1 | ||
100 | -41.101 | ||
150 | -41.3 | ||
300 | -41.2 | ||
|
||
Write the code in SQL with duckdb to perform left join between tables A and B based on column 'id' so that the logitude of an 'id' will be the average of longitudes in table B weighted by the difference between the numbers in table A and table B | ||
|
||
|
||
|
||
|
||
"SELECT | ||
A.id, | ||
SUM((1/ABS(A.number - B.number) * B.longitude)) / SUM(1/ABS(A.number - B.number)) AS weighted_avg_longitude | ||
FROM | ||
tableA AS A | ||
LEFT JOIN | ||
tableB AS B | ||
ON | ||
A.number = B.number | ||
GROUP BY | ||
A.id;" |