Skip to main content
5 of 5
edited body
Paul White
  • 90.3k
  • 30
  • 423
  • 663

I might not understand the problem, but:

SELECT my_sum, my_sum, my_sum
FROM (
    SELECT   SUM(t.customers) FILTER (
               WHERE id = 1
               AND date BETWEEN %(start)s AND %(stop)s
         ) + SUM(t.employees) FILTER (
               WHERE id = 1
               AND date BETWEEN %(start)s AND %(stop)s
         )  as my_sum
    FROM t
) AS tt;

If the filters are always the same, it may be better to move them to a where clause:

SELECT my_sum, my_sum, my_sum
FROM (
    SELECT SUM(t.customers) + SUM(t.employees) as my_sum
    FROM t
    WHERE id = 1
    AND date BETWEEN %(start)s AND %(stop)s
) AS tt;

Fiddle