Skip to content

Commit

Permalink
improve sql query
Browse files Browse the repository at this point in the history
Also-by: Matthias Feurer m.feurer@sotec.eu
Signed-off-by: georgios dimitropoulos <g.dimitropoulos@sotec.eu>
Signed-off-by: g.dimitropoulos <g.dimitropoulos@sotec.eu>
  • Loading branch information
gdimitropoulos-sotec committed Sep 12, 2023
1 parent 6d25e86 commit c9048a0
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -71,18 +71,20 @@ countGatewaysOfTenant: |
SELECT replace(dr.device_id::text, '"', '') FROM (
SELECT jsonb_array_elements(data -> 'via') AS device_id FROM device_registrations
WHERE tenant_id=:tenant_id AND data ->> 'via' != '')
as dr)
as dr)
countOnlyDevicesOfTenant: |
SELECT COUNT(*) AS deviceCount FROM %1$s
SELECT (SELECT COUNT(*) FROM %1$s WHERE tenant_id=:tenant_id)
-
(SELECT COUNT(*) AS deviceCount FROM %1$s
WHERE
tenant_id=:tenant_id
AND
device_id NOT IN (
device_id IN (
SELECT replace(dr.device_id::text, '"', '') FROM (
SELECT jsonb_array_elements(data -> 'via') AS device_id FROM device_registrations
WHERE tenant_id=:tenant_id AND data ->> 'via' != '')
as dr)
WHERE tenant_id=:tenant_id AND data ->> 'via' != '')
as dr)) AS deviceCount
findDevicesOfTenantWithFilter: |
SELECT *

0 comments on commit c9048a0

Please sign in to comment.