Name
MAKE_SET()
Synopsis
MAKE_SET(bits
,string1
,string2
, ...)
This function converts the decimal number in
bits
to binary and returns a comma-separated list of values for all
the bits that are set in that number, using
string1
for the low-order bit,
string2
for the next lowest bit, etc. Here
is an example:
SELECT BIN(9) AS 'Binary 9', MAKE_SET(100, 'A','B','C','D') AS Set; +----------+------+ | Binary 9 | Set | +----------+------+ | 1001 | A,D | +----------+------+
The binary equivalent of 9 is 1001. The first bit starting from
the right of the binary number shown is 1 (or
on), so the first string in the list is put into
the results. The second and third bits of the binary number are 0, so
the second and third strings ('B'
and
'C'
) are left out of the results. The fourth bit
counting from the right is 1, so the fourth string of the list is
added to the results.
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.