I am trying to get a "total override" but only sum if the agent = x,y or z
SELECT
DISTINCT( "public"."rdf_dean"."agent_name" ) AS "Agent",
SUM("public"."rdf_dean"."paidcomm" *.9) AS "Paid to Agent",
SUM("public"."rdf_dean"."paidcomm" *.1) AS "Overrides",
SUM overrides IF agent_name = x OR agent_name = y OR agent_name = z
FROM "public"."rdf_dean"
WHERE "public"."rdf_dean"."created_date" = date(now())
GROUP BY agent_name
You use the SUMIF function to sum the values in a range that meet criteria that you specify. For example, suppose that in a column that contains numbers, you want to sum only the values that are larger than 5. You can use the following formula: =SUMIF (B2:B25,">5") This video is part of a training course called Add numbers in Excel.
The equivalent SUMIFS formula is: = SUMIFS(amount, amount,">1000") Notice that the sum range always comes first in the SUMIFS function. Also note that SUMIFS criteria need to be entered in pairs (range / criteria) which means the named range "amount" must be entered twice: once as the sum range, and once as a criteria range.
The syntax of SUMIFS is; SUMIFS (sum_range, criteria_range1, criteria1, criteria_range2, criteria2,...) Suppose, you want to sum the orders’ amounts that are delivered between two dates then you will use SUMIFS function. Here you need to supply two criteria on the same range and where both of these criteria are met SUMIFS function sums those ...
SUMIFS requires a range, you can't substitute an array. To sum if less than, you can use the SUMIF function. In the example shown, cell H5 contains this formula: =SUMIF (amount,"<1000") Where "amount" is a named range for cells D5:D11. This formula sums the...
If you want to have both aggregates for all rows and for some you can use FILTER (https://www.postgresql.org/docs/9.4/static/sql-expressions.html):
SELECT
"public"."rdf_dean"."agent_name" AS "Agent",
SUM("public"."rdf_dean"."paidcomm" *.9) AS "Paid to Agent",
SUM("public"."rdf_dean"."paidcomm" *.1) AS "Overrides",
SUM("public"."rdf_dean"."paidcomm" *.1)
FILTER (WHERE agent_name = x OR agent_name = y OR agent_name = z)
AS "Partial Overrides",
FROM "public"."rdf_dean"
WHERE "public"."rdf_dean"."created_date" = date(now())
GROUP BY agent_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With