SELECT [Cole_Crops],
PERCENT_RANK() OVER (PARTITION BY HUC02
ORDER BY [Cole_Crops]) AS Cole_Crops_PCT_RANK],
[Row_Crops],
PERCENT_RANK() OVER (PARTITION BY HUC02
ORDER BY [Row_Crops]) AS Row_Crops_PCT_RANK]
FROM V012_CDLMAX_09
How do you exclude NULL values from affecting the PERCENT_RANK in a query with multiple columns to be ranked?
SQL Server 2012 PERCENT_RANK()
treats NULLS as a real value in the distribution. If there were one column to be ranked, you can simply add a where clause (i.e., where Cole_Crops IS NOT NULL
).