I have a bitfield called warnings stored as an int. I would like to get a list of warnings for each person
lets say we have a table
NAME, WARNINGS
alex, 0
mike, 5
sarah, 2
where each bit of the integer corresponds to a warning # (bit position). This is currently done in perl with a for loop
for(my $i=0; $i < $warning_size;$i++ ){
if( (1 << $i ) & $warning != 0){
print "$name\t" . $i+1 ."\n";
}
}
Is there any way that I can have this handled by a mysql query.
For the above example, I would like the following output:
name, warning
-------------
mike 1
mike 3
sarah 2
I am trying to get this down to one select statement,
Thanks