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

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -