SUMIFS in SQL
SUMIFS adds up values that meet several conditions at once; in SQL each condition becomes part of the WHERE clause.
The Excel version
=SUMIFS(C:C, B:B, "West", D:D, ">="&DATE(2026,1,1), D:D, "<"&DATE(2026,2,1))The SQL equivalent
This example assumes: sales(id bigint, region text, amount numeric, sale_date date). It is written in PostgreSQL syntax, and your table and column names will differ from these.
SELECT COALESCE(SUM(amount), 0) AS west_sales_january
FROM sales
WHERE region = 'West'
AND sale_date >= DATE '2026-01-01'
AND sale_date < DATE '2026-02-01';How it works
- Each criteria pair in SUMIFS becomes one condition joined with AND.
- The half-open date range (>= start, < next month) avoids missing times on the last day.
- COALESCE turns the null that SUM returns for no rows into 0, matching Excel.
Where the results differ from Excel
- All SUMIFS criteria are combined with AND; for OR logic in SQL use OR or IN (...), which SUMIFS cannot do in one formula.
- Text criteria in Excel are case-insensitive; SQL's equality is case-sensitive in PostgreSQL.
- Blank cells and empty strings behave differently from nulls; test with IS NULL when a criterion should match blanks.
Skip the query: ask in plain English
If you would rather not write SQL, type the question. SchemaChat turns it into SQL against your connected database or uploaded file, runs it, and shows the SQL and the figures it used so you can check the answer before you share it. Check that the result matches how your spreadsheet defines the number.
- What were West region sales in January 2026?
- Total sales by region for each month this year.