On 2016/10/17 4:47 PM, Daniel Polski wrote:

select unit, sum(1 << bit_position) from table1 where val group by unit;


To make it more complex.. Is it possible to select into "different bytes" depending on bit_position? (For example that bit_position 0-7 represent byte 1, bit_position 8-15 represent another)

To get a second "byte" I can tweak your initial idea to:

select unit, sum(1 << (bit_position-9)) from table1 where val and bit_position between 8 and 15 group by unit;

But that would need to get merged into the initial solution some way on the same select row result.


select unit, (bit_position / 8) AS byteNo, (sum(1 << (bit_position % 8)) AS byteVal from table1 where val group by unit, (bit_position / 8);


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to