Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you said, you cannot change it, but one easy solution for these cases are the Bitwise:</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html</a></p> <p>eg:</p> <p>I set a number scheme for the status such as:<br> 1 = Prospective Customer<br> 2 = Cancelled Service<br> 4 = Pool Service<br> 8 = lawn mowing<br> 16 = window washing<br> 32 = tree trimming<br> 64 = house painting<br> 128 = mobile oil change </p> <p>With this scheme a customer who needs pool service (4) and window washing (16) will have a status of 20 (4 + 16). A prospect (1) who might be interested in a mobile oil change (128) would have a status of 129 (1+128). etc...</p> <p>Bitwise logic allows me to select customers who buy particular services based on their status value.</p> <pre><code>SELECT * FROM customers WHERE status &amp; 1 //returns all prospects) SELECT * FROM customers WHERE status &amp; 16 //returns all of my window washing customers even if they are cancelled SELECT * FROM customers WHERE (status &amp; 16) AND !(status &amp; 2) //returns all of my window washing customers but not the cancelled ones SELECT * FROM customers WHERE status &amp; 36 //returns all of my tree trimming AND pool service customers i.e. 32+4 SELECT * FROM customers WHERE status &amp; 10 //returns all cancelled lawn moving customers i.e. 2+8 SELECT * FROM customers WHERE (status &amp; 32) AND !(status &amp; 128) //returns all tree trimming customers who do not get a mobile oil change </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload