Skip to content
ferkesh.HOSTING

Reconcile MySQL Counts When Columns Can Be NULL

Developer Resources 56 visualizações Markdown

In MySQL COUNT(*) counts rows in a result. COUNT(column) counts rows with a non-NULL value for that expression. Two dashboards can show different totals without disagreeing about which rows match a filter.

Filtered result: Three rows; COUNT of column: Two dates; Report definition: Name what is counted.

Compare a defined fixture

Imagine three synthetic orders. Two have shipped_at dates and one has NULL. With the same filter COUNT(*) is three and COUNT(shipped_at) is two. Check what a populated date actually represents before naming the metric.

Check query shape

Use the same filters, joins and date range before comparing counts. A one-to-many join can multiply rows. A filter placed on the right-side table can change which unmatched rows appear. Verify expected group counts using a small read-only staging sample.

Document the intended measure

Use plain labels such as eligible orders and orders with a recorded shipment date. Test empty and NULL cases. Use an approved read-only role in production and make reporting changes only against the agreed definition.

Official references

Last reviewed .

Foi útil?

Obrigado pela sua opinião!

Ainda precisa de ajuda?

A equipa de apoio está disponível a qualquer hora para ajudar com o que não encontrar na base de conhecimento.