Skip to content
Advertisement

Teradata get row counts for previous two days and compare

I’m trying to setup a data check, where we get the row count from a table for today and prior date. Since it isn’t loaded on weekends or holidays, I can’t say DATE-1.

I came-up with the following, to get the previous date:

This produces the dates, counts and assigns a row number.

I to take the two most current dates and compare them. Most current would be “current” and the 2nd most current would be “prior” . Then I would like to have something like this as the result set:

My issue is, how do I reference the first two rows and compare them to each other? Unless I’m over-thinking this, I need two additional SELECT statements: 1 with the WHERE clause referencing row 1 and another with a WHERE referercing row 2.

How do I do that? Do I have two CTEs?
Eventually, I’ll need a third SELECT dividing the two rows and checking for 10% tolerance. Help, I’m in analysis paralysis.

Advertisement

Answer

You can filter the result of an OLAP-function using QUALIFY:

checking for 10% tolerance:

Either ANDed to the QUALIFY or within a CASE

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement