zorm icon indicating copy to clipboard operation
zorm copied to clipboard

Annotated values

Open chaitanyagupta opened this issue 5 years ago • 0 comments

Annotated values are columns returned by the query in addition to columns of the table which is primarily being queried. For example, if we have an organizations and an employees table linked by organization_id, we can annotate the employee count for each organization like so:

WITH employee_counts AS 
  (SELECT organization_id, count(*) FROM employees GROUP BY organization_id)
SELECT organization_id, name, count AS employee_count FROM organizations JOIN employee_counts USING (organization_id);

chaitanyagupta avatar Jun 01 '19 06:06 chaitanyagupta