lighter
lighter

Reputation: 2806

sql check column value included 2

My column type is Number, and this number rule is

1,2 => 3 
1,2,4 => 7
2,4 => 6

Finally, I will save the result, ex 3, 7, 6.

It's a sum of binary. can I check include 2 on the where condition? Thanks your help.


edit

example

| id | type | data |
|----|------|------|
| 1  |  2   | test |
| 2  |  3   | test2|
| 3  |  1   | test3|
| 4  |  6   | test4|

The result is I want.

| id | type | data |
|----|------|------|
| 1  |  2   | test |
| 2  |  3   | test2|
| 4  |  6   | test4|

sql ex

select * from test_table where type "include 2";

Upvotes: 0

Views: 24

Answers (1)

lighter
lighter

Reputation: 2806

I found the answer for my goal. I can use bitand function here.

select * from test_table where bitand(type, 2) = 2;

Upvotes: 1

Related Questions