sql server - TSql Return column based on partition and rownumber -
i have sql server table i'm attempting computed column - mypartition - indicating number of partition based on variable @segment. example, if @segment = 3 following output true.
rowid | rowname | mypartition ------ | -----------| ------- 1 | prod 1 | 1 2 | prod 2 | 1 3 | prod 3 | 1 4 | prod 4 | 2 5 | prod 5 | 2 6 | prod 6 | 2 7 | prod 7 | 3 8 | prod 8 | 3 9 | prod 9 | 3 10 | prod 10 | 4 what have far like:
select rowid, rowname, row_number() over(partition rowid order rowid asc) mypartition mytable order rowid but can guess partition partitions on rowid giving values of mypartition = 1. unsure how structure partition clause achieve this.
how about
ceiling(row_number() over(order rowid asc) / 3.0)
Comments
Post a Comment