Sql NTILE() function with Postalcode -


i trying split records in equal number of decks. works fine sql ntile(20) function. issue splits post code well. splitting should happen within postcode.

select (ntile(20) over(order postalcode asc)) 'decknumber'  xxx  order postalcode 

any ideas how solve ?

enter image description here

if you're using sql server - should able this:

select     ntile(20) over(partition postalcode order postalcode asc) 'decknumber'  dbo.xxx  order postalcode 

this "partition" data groups postalcode, , inside each group, ntile(20) function applied.

maybe want use different order by clause inside ntile...over() function - since you're partitioning postalcode, ordering doesn't make whole lot of sense...


Comments

Popular posts from this blog

Python __call__ special method practical example -

arrays - jQuery - Retrieve values from HTML elements and return their sum -