Skip to main content
edited body
Source Link
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 filter'sfilters 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

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 filter's 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

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

added 52 characters in body
Source Link

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 filter's 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

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 filter's 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;

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 filter's 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

added 14 characters in body
Source Link

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+ SUM(t.employees) FILTER (
               WHERE id = 1
        AND date 
      AND date BETWEEN %(start)s AND %(stop)s
         )  as my_sum
    FROM t
) AS tt;

If the filter's 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;

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;

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 filter's 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;
added 102 characters in body
Source Link
Loading
Post Undeleted by Lennart - Slava Ukraini
Post Deleted by Lennart - Slava Ukraini
Source Link
Loading