Excel → T-SQL › SUMIFS

SUMIFS to SQL SUM with AND

Excel puts the sum range first. SQL does not. Write SUM(amount) and list the tests in WHERE.

SELECT SUM(total_amount)
FROM Orders
WHERE status = 'Shipped'
  AND customer_id = @customer_id;

Per customer is GROUP BY customer_id, not a copy-pasted SUMIFS down a sheet.

Canonical translation

SELECT SUM(total_amount)
FROM Orders
WHERE status = 'Shipped'
  AND customer_id = @customer_id;

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free