I've been looking at how to do a bitwise-OR aggregation in TSQL in a subquery, and the answers given in a popular question don't seem to maintain partitioning. Is there any way for me to partition?
Let's say we have the following data:
id | someCount | someFlags
1 | 2 | 0
1 | 3 | 2
1 | 0 | 1
2 | 1 | 4
2 | 5 | 0
2 | 1 | 1
I can get the SUM
of the someCount
field partitioned by id
without losing any of the original rows like so:
SELECT [testSum] = SUM([someCount]) OVER (PARTITION BY [id]) FROM myTable
Is there a way to do this with a bitwise OR operation? so I'd get:
id | value
1 | 3
1 | 3
1 | 3
2 | 5
2 | 5
2 | 5