// aggregates reference

SQL REGR_COUNT function

Counts the complete input pairs the regression functions actually use.

Categoria
Aggregates
Returns
bigint
In this category
30 of 52

Sintaxe

REGR_COUNT(y, x)

Suporte a mecanismos

MotorSupportNotas
SQL Server Not built in COUNT(CASE WHEN y IS NOT NULL AND x IS NOT NULL THEN 1 END)
PostgreSQL Sim Supported under this name.
MySQL Not built in portable recipe: COUNT(*) with both columns non-NULL in WHERE
SQLite Not built in COUNT(CASE WHEN y IS NOT NULL AND x IS NOT NULL THEN 1 END)
Oracle Sim Supported under this name.

Exemplos

PostgreSQL

SELECT regr_count(sales, ad_spend) FROM monthly;

SQL Server

SELECT COUNT(CASE WHEN sales IS NOT NULL AND ad_spend IS NOT NULL THEN 1 END) FROM monthly;

Bom saber

  • It is the denominator behind every other REGR_ decision: the whole family works on complete pairs only.
  • Never returns NULL: an empty group yields 0, like COUNT.
  • The portable recipe is a filtered COUNT: COUNT(CASE WHEN y IS NOT NULL AND x IS NOT NULL THEN 1 END).

Questions about REGR_COUNT

REGR_COUNT vs COUNT(*)?

COUNT(*) counts rows; REGR_COUNT(y, x) counts rows where both y and x are non-NULL.

Can it return NULL?

No, it returns 0 for an empty group like COUNT does.

Which engines have it?

PostgreSQL and Oracle; everywhere else use the filtered COUNT recipe.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.