Saliceran Saliceran - 3 months ago 13
SQL Question

How do I get the average row count per day of data?

I have a large table in Teradata that gets new data loaded into it daily. It has a column called

CAL_DT
that is the date that row was loaded into the table. I'd like to write a query that will give me the average row count per day so I can see how much data generally gets loaded in a day.

Answer

You can count the number of rows and divide by the number of days:

select count(*) / count(distinct cal_dt)
from t;

This gives the average for each day when data was loaded.