diff options
author | Starfall <us@starfall.systems> | 2020-12-24 13:36:25 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2020-12-24 13:36:25 -0600 |
commit | 6ed4e874c5ace36344f77b3f096c4089d9b11e01 (patch) | |
tree | 83b2675d297f56a75b5e5dec33c644bc19f6cf1b /db/views | |
parent | ab127fd7941b7c84e6d6fe3071d41f52affb143c (diff) | |
parent | 225c934a1b66e2fcbedbda7936666c1ca3c9a04b (diff) |
Merge branch 'glitch' into main
Diffstat (limited to 'db/views')
-rw-r--r-- | db/views/instances_v01.sql | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/db/views/instances_v01.sql b/db/views/instances_v01.sql new file mode 100644 index 000000000..94acd61a1 --- /dev/null +++ b/db/views/instances_v01.sql @@ -0,0 +1,17 @@ +WITH domain_counts(domain, accounts_count) +AS ( + SELECT domain, COUNT(*) as accounts_count + FROM accounts + WHERE domain IS NOT NULL + GROUP BY domain +) +SELECT domain, accounts_count +FROM domain_counts +UNION +SELECT domain_blocks.domain, COALESCE(domain_counts.accounts_count, 0) +FROM domain_blocks +LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_blocks.domain +UNION +SELECT domain_allows.domain, COALESCE(domain_counts.accounts_count, 0) +FROM domain_allows +LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_allows.domain |