Skip to content

Instantly share code, notes, and snippets.

@aguimaraes
Last active September 4, 2015 13:00
Show Gist options
  • Select an option

  • Save aguimaraes/1f4edfdeb9b0a133238f to your computer and use it in GitHub Desktop.

Select an option

Save aguimaraes/1f4edfdeb9b0a133238f to your computer and use it in GitHub Desktop.
select fancy_name, (select name from cities where id = persons.addr_city_id) as city, addr_uf,
(select count(*) from ctes where owner_id = persons.id and created_at >= '2015-06-01 00:00:00') as ctes,
(select count(*) from incomes where owner_id = persons.id and created_at >= '2015-06-01 00:00:00') as incomes
from persons
where owner_id is null
and ((select count(*) from ctes where owner_id = persons.id and created_at >= '2015-06-01 00:00:00') > 0
or (select count(*) from incomes where owner_id = persons.id and created_at >= '2015-06-01 00:00:00') > 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment