我有一列使用位来记录每个任务的状态。位的索引表示任务的数量,而1/0表示此任务是否成功,并且所有位(尽管放在一起)在逻辑上是隔离的。
例如:1010以十进制存储,表示用户成功完成了第二次和第四次任务,该表如下所示:
uid status
a 1100
b 1111
c 1001
d 0100
e 0011
Now I need to calculate the passing rate of each mission.
I can use a formula FLOOR(status%POWER(10,n)/POWER(10,n-1))
to get the bit of every mission of every user, but actually this means I need to run my query by n times and now the status is 64-bit long...
有没有一种优雅的方法可以在一个查询中做到这一点?任何帮助表示赞赏。