T-SQL 101: 92 Categorizing output rows by using NTILE
I’ve been talking about the basic window functions in T-SQL and one that’s not well known but is surprisingly useful is NTILE.
I’m not sure on the name but it’s probably short for percentile. I don’t know why they didn’t call it a slightly more meaningful name, but what it says is take the output and break it up into bands or chunks of data.
So if I say NTILE(10), that’ll give me a tenth of the rows with a value of 1, another tenth of the rows with a value of 2, and so on.
2021-03-29