Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MySQL Operators

2,658 views

Published on

MySQL Operators

Published in: Technology, Economy & Finance
  • Be the first to comment

  • Be the first to like this

MySQL Operators

  1. 1. MYSQL OPERATORS<br />
  2. 2. OverviewPrecedence of operators and type conversionArithmetic operatorsBitwise operatorsLogical operatorsComparison operatorsMathematical functionsString functionsDate functions<br />
  3. 3. Precedence of operators<br />1.Interval<br />2.binary,collate<br />3.!<br />4.-(unary minus),~(unary bit inversion)<br />5.^<br />6.*,/, div, %, mod<br />7.+,-<br />
  4. 4. 8.&lt;&lt;, &gt;&gt;<br />9.&<br />10.|<br />11. =, &lt;=&gt;, &gt;=, &gt;, &lt;=, &lt;, &lt;&gt;, !=, IS, LIKE, REGEXP, IN<br />12.between,case,when,then,else<br />13.Not<br />14.&&,and<br />15.Xor<br />16.||, or<br />17. :=<br />
  5. 5. Ex:<br />Mysql&gt;select 3-2%1;<br />3<br />Mysql&gt;select 4+5-1/2*2;<br />8.0000<br />Mysql&gt;select 23+13&&13;<br />1<br />
  6. 6. ARITHMATIC OPERATORS<br />
  7. 7. All arithmetic operations are calculated with BIGINT(64-bit) precision.<br />Ex:<br />Mysql&gt;select 4+55;<br />59<br />Mysql&gt;select 4-55;<br />-51;<br />Mysql&gt;select -5;<br />-5 (unary minus)<br />
  8. 8. Mysql&gt;select 122%45;<br />32<br />Mysql&gt;select 100/0;<br />NULL<br />Mysql&gt;select 10/3;<br />3.3333<br />Mysql&gt;select 10 div 3;<br />3 (integer division)<br />
  9. 9. BITWISE OPERATORS<br />
  10. 10. All the operands should be numerals, but they are internally represented as binary.<br />Left shift(&lt;&lt;)<br />Mysql&gt;select 4&lt;&lt;2;<br />16<br />Right shift(&gt;&gt;)<br />Mysql&gt;select 4&gt;&gt;2;<br />1<br />
  11. 11. Bitwise OR(|)<br />Mysql&gt;select 23|12;<br />31<br />Bitwise AND(&)<br />Mysql&gt;select 23&12;<br />4<br />Bitwise XOR(^)<br />Mysql&gt;select 1^1;<br />0<br />
  12. 12. Mysql&gt;select 0^1;<br />1<br />Mysql&gt;select 0^0;<br />0<br />Bitwise NOT<br />Mysql&gt;select 5&~1;<br />4<br />Mysql&gt;select 6&~6;<br />0<br />
  13. 13. LOGICAL OPERATORS<br />
  14. 14. Ex:<br />Mysql&gt;create table employee(<br />Ssn INT NOT NULL,<br />Salary INT,<br />Name VARCHAR(20),<br />Department VARCHAR(20),<br />Primary key(ssn));<br />Mysql&gt;insert into employee<br />Values(100,10000,’sneha’,’finance’);<br />
  15. 15. Mysql&gt;insert into employee<br />Values(200,20000,’shalini’,’hr’);<br />Mysql&gt;insert into employee<br />Values(300,30000,’john’,’finance’);<br />Mysql&gt;insert into employee<br />Values(400,40000,’jack’,’hr’);<br />
  16. 16. Mysql&gt;select * from employee;<br />
  17. 17. Logical AND<br />Mysql&gt;select ssn, name from employee where salary&gt;10000 && salary&lt;40000;<br /><br />
  18. 18. Logical OR<br />mysql&gt;select name, salary, ssn from employee where<br />Name like ‘%s’ || department like ‘%f’;<br /><br />
  19. 19. Logical NOT<br />mysql&gt;select name, department from employee where ssn!=100;<br /> <br />
  20. 20. Comparison operatorsThese operators return 1 if true else 0 if the condition is false<br />
  21. 21. Returns 1 if the condition is TRUE and returns 0 if the condition is FALSE<br />Mysql&gt;select 2.34&lt;=2.34;<br />1<br />Mysql&gt;select 2.34&lt;=1.24;<br />0<br />Mysql&gt;select 4.2&gt;=4;<br />1<br />
  22. 22. Mysql&gt;select 10!=10;<br />o<br />Mysql&gt;select 5!=10;<br />1<br />Mysql&gt; select 3 between 1 and 4;<br />1<br />Mysql&gt;select greatest(10,20,99);<br />99<br />
  23. 23. MATHEMATICAL FUNCTIONS<br />
  24. 24.
  25. 25.
  26. 26. Mysql&gt;select cos(89);<br />0.510177044941669<br />Mysql&gt;select atan(90);<br />1.55968567289729<br />Mysql&gt;select floor(1.34);<br />1<br />Mysql&gt;select ceil(1.34);<br />2<br />Mysql&gt;select format(234567.34356,3)<br />234,567.344<br />
  27. 27. Mysql&gt;select pi();<br />3.141593<br />Mysql&gt;select radians(90);<br />1.5707963267949<br />Mysql&gt;select degrees(1.57);<br />89.9543738355392<br />Mysql&gt;select truncate(4.34,1);<br />4.3<br />Mysql&gt;select truncate(23.22,-1);<br />20<br />
  28. 28. STRING FUNTIONS<br />
  29. 29. Mysql&gt;select concat(“winners”, ”attitude”);<br />winnersattitude<br />Mysql&gt;select concat_ws(‘$’,’pope’,’ john’, ’paul’);<br />pope$john$paul<br />(concats the strings by placing the separator in between the strings)<br />Mysql&gt;select char_length(‘mysql’);<br />5<br />
  30. 30. Mysql&gt;select lcase(‘OPERATORS’);<br />operators<br />Mysql&gt;select length(‘personalexcellence’);<br />18<br />Mysql&gt;select locate(‘point’, ’powerpoint’);<br />6<br />(returns the position of the substring in the mainstring)<br />
  31. 31. Mysql&gt;select repeat(‘win’,3);<br />winwinwin<br />Mysql&gt;select replace(‘myindia’, ’my’, ’our’);<br />ourindia<br />Mysql&gt;select reverse(‘apple’);<br />elppa<br />
  32. 32. Mysql&gt;select substring(‘mysql’,3);<br />sql<br />(returns the substring at the given position from the main string)<br />Mysql&gt;select format(233444.564678,3);<br />233,444.565<br />(formats the given string and rounds to the given digits after the decimal point)<br />
  33. 33. DATE FUNCTIONS<br />
  34. 34. Ex:<br />Mysql&gt;select curdate();<br />2009-12-29<br />Mysql&gt;select curtime();<br />13:04:21<br />Mysql&gt;select now();<br />2009-12-29 13:05:12<br />
  35. 35. Mysql&gt;select monthname(‘2009-10-09’);<br />october<br />Mysql&gt;select month(‘2009-10-09’);<br />10 (returns the month in numeric format)<br />Mysql&gt;select minute(‘13:05:12’);<br />5<br />Mysql&gt;select hour(‘13:05:12’);<br />13<br />
  36. 36. Mysql&gt;select dayname(‘2010-01-01’);<br />Friday<br />Mysql&gt;select dayofmonth(‘2010-01-01’);<br />1 (returns the day in the range 1 to 31)<br />Mysql&gt;select dayofweek(‘2010-21-01’):<br />5 (returns the day in the range 1 to 7)<br />
  37. 37. Mysql&gt;select datediff(‘2009-1-1’,’2009-10-10’);<br />83 <br />(returns the difference between the dates in days)<br />Mysql&gt;select date_add(‘2009-12-29’,interval 3 day);<br />2010-01-01<br />(returns the new date formed after adding the number of days mentioned in the interval)<br />
  38. 38. SOME OF THE APPLICATIONS OF MYSQL OPERATORS;1.operators and functions are used for performing calculations on stored values.2.High performance text search, field search and text editing applications.3.NAND,NOR AND XOR operators are are used in electrical applications.<br />
  39. 39. Visit more self help tutorials<br />Pick a tutorial of your choice and browse through it at your own pace.<br />The tutorials section is free, self-guiding and will not involve any additional support.<br />Visit us at www.dataminingtools.net<br />

×