Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

join - aggregate - join bleeds out join from subselect #114

Open
bendlas opened this issue Oct 5, 2011 · 1 comment
Open

join - aggregate - join bleeds out join from subselect #114

bendlas opened this issue Oct 5, 2011 · 1 comment
Labels

Comments

@bendlas
Copy link
Collaborator

bendlas commented Oct 5, 2011

Join two tables, aggregate over the join, join onto another table:

(join (table :workgroups)
      (-> (table :employees)
          (join (table :salaries) :emp_id)
          (aggregate [:avg/salaries.salary] [:workgroup_id]))
      :workgroup_id)

Expected: Something like

SELECT workgroups.*,employees_subselect.workgroup_id 
  FROM workgroups 
  JOIN (SELECT employees.workgroup_id,avg(salaries.salary) 
          FROM employees 
          JOIN salaries USING(emp_id) 
         GROUP BY employees.workgroup_id) AS employees_subselect
 USING (workgroup_id)

Actual: The inner join bleeds out of the subselect, also a field is double - selected:

SELECT workgroups.*,employees_subselect.workgroup_id,employees_subselect.workgroup_id
  FROM workgroups 
  JOIN (SELECT employees.workgroup_id,avg(salaries.salary) 
          FROM employees 
          JOIN salaries USING(emp_id) 
         GROUP BY employees.workgroup_id) AS employees_subselect
 USING (workgroup_id) 
  JOIN salaries USING(emp_id)
@LauJensen
Copy link
Owner

Bendlas have you pinpointed the cause yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants