Getting the population of a table partitioned by date

When you have to troubleshoot some queries, it’s always interesting to get the population of a table by partition. We all know the query that gives you the count by partition number

SELECT 
    PARTITION, 
    COUNT(*) 
FROM 
    BASE.TABLE 
GROUP BY PARTITION 
ORDER BY PARTITION ASC

Here is a query that will return the count with the actual ranges defined

Table DDL

CREATE MULTISET TABLE BASE.TABLE1 ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      TABLE_ID VARCHAR(32) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
      CONTACT_KEY VARCHAR(250) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
      SEND_DT DATE FORMAT 'YYYY-MM-DD'
      )
PRIMARY INDEX PI_A_ECRM_SEND (TABLE_ID, SEND_DT )
PARTITION BY RANGE_N(SEND_DT  BETWEEN DATE '2015-11-30' AND DATE '2019-02-17' EACH INTERVAL '7' DAY , NO RANGE,UNKNOWN);

Query to get the population of Ranges with the defined ranges

LOCKING BASE.TABLE1 FOR ACCESS
SELECT
    PARTITION AS PARTITION_NUMBER,
    MIN(SEND_DT) AS RANGE_LOW,
    MAX(SEND_DT) AS RANGE_HIGH,
    COUNT(*) AS POPULATION
FROM BASE.TABLE1
GROUP BY PARTITION
ORDER BY PARTITION ASC

Displaying the result

You clearly also get the UNKNOW and NO RANGE Partitions