• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MySQL Operators
 

MySQL Operators

on

  • 2,543 views

MySQL Operators

MySQL Operators

Statistics

Views

Total Views
2,543
Views on SlideShare
2,525
Embed Views
18

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 18

http://www.dataminingtools.net 12
http://dataminingtools.net 6

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MySQL Operators MySQL Operators Presentation Transcript

    • MYSQL OPERATORS
    • OverviewPrecedence of operators and type conversionArithmetic operatorsBitwise operatorsLogical operatorsComparison operatorsMathematical functionsString functionsDate functions
    • Precedence of operators
      1.Interval
      2.binary,collate
      3.!
      4.-(unary minus),~(unary bit inversion)
      5.^
      6.*,/, div, %, mod
      7.+,-
    • 8.<<, >>
      9.&
      10.|
      11. =, <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
      12.between,case,when,then,else
      13.Not
      14.&&,and
      15.Xor
      16.||, or
      17. :=
    • Ex:
      Mysql>select 3-2%1;
      3
      Mysql>select 4+5-1/2*2;
      8.0000
      Mysql>select 23+13&&13;
      1
    • ARITHMATIC OPERATORS
    • All arithmetic operations are calculated with BIGINT(64-bit) precision.
      Ex:
      Mysql>select 4+55;
      59
      Mysql>select 4-55;
      -51;
      Mysql>select -5;
      -5 (unary minus)
    • Mysql>select 122%45;
      32
      Mysql>select 100/0;
      NULL
      Mysql>select 10/3;
      3.3333
      Mysql>select 10 div 3;
      3 (integer division)
    • BITWISE OPERATORS
    • All the operands should be numerals, but they are internally represented as binary.
      Left shift(<<)
      Mysql>select 4<<2;
      16
      Right shift(>>)
      Mysql>select 4>>2;
      1
    • Bitwise OR(|)
      Mysql>select 23|12;
      31
      Bitwise AND(&)
      Mysql>select 23&12;
      4
      Bitwise XOR(^)
      Mysql>select 1^1;
      0
    • Mysql>select 0^1;
      1
      Mysql>select 0^0;
      0
      Bitwise NOT
      Mysql>select 5&~1;
      4
      Mysql>select 6&~6;
      0
    • LOGICAL OPERATORS
    • Ex:
      Mysql>create table employee(
      Ssn INT NOT NULL,
      Salary INT,
      Name VARCHAR(20),
      Department VARCHAR(20),
      Primary key(ssn));
      Mysql>insert into employee
      Values(100,10000,’sneha’,’finance’);
    • Mysql>insert into employee
      Values(200,20000,’shalini’,’hr’);
      Mysql>insert into employee
      Values(300,30000,’john’,’finance’);
      Mysql>insert into employee
      Values(400,40000,’jack’,’hr’);
    • Mysql>select * from employee;
    • Logical AND
      Mysql>select ssn, name from employee where salary>10000 && salary<40000;

    • Logical OR
      mysql>select name, salary, ssn from employee where
      Name like ‘%s’ || department like ‘%f’;

    • Logical NOT
      mysql>select name, department from employee where ssn!=100;

    • Comparison operatorsThese operators return 1 if true else 0 if the condition is false
    • Returns 1 if the condition is TRUE and returns 0 if the condition is FALSE
      Mysql>select 2.34<=2.34;
      1
      Mysql>select 2.34<=1.24;
      0
      Mysql>select 4.2>=4;
      1
    • Mysql>select 10!=10;
      o
      Mysql>select 5!=10;
      1
      Mysql> select 3 between 1 and 4;
      1
      Mysql>select greatest(10,20,99);
      99
    • MATHEMATICAL FUNCTIONS
    • Mysql>select cos(89);
      0.510177044941669
      Mysql>select atan(90);
      1.55968567289729
      Mysql>select floor(1.34);
      1
      Mysql>select ceil(1.34);
      2
      Mysql>select format(234567.34356,3)
      234,567.344
    • Mysql>select pi();
      3.141593
      Mysql>select radians(90);
      1.5707963267949
      Mysql>select degrees(1.57);
      89.9543738355392
      Mysql>select truncate(4.34,1);
      4.3
      Mysql>select truncate(23.22,-1);
      20
    • STRING FUNTIONS
    • Mysql>select concat(“winners”, ”attitude”);
      winnersattitude
      Mysql>select concat_ws(‘$’,’pope’,’ john’, ’paul’);
      pope$john$paul
      (concats the strings by placing the separator in between the strings)
      Mysql>select char_length(‘mysql’);
      5
    • Mysql>select lcase(‘OPERATORS’);
      operators
      Mysql>select length(‘personalexcellence’);
      18
      Mysql>select locate(‘point’, ’powerpoint’);
      6
      (returns the position of the substring in the mainstring)
    • Mysql>select repeat(‘win’,3);
      winwinwin
      Mysql>select replace(‘myindia’, ’my’, ’our’);
      ourindia
      Mysql>select reverse(‘apple’);
      elppa
    • Mysql>select substring(‘mysql’,3);
      sql
      (returns the substring at the given position from the main string)
      Mysql>select format(233444.564678,3);
      233,444.565
      (formats the given string and rounds to the given digits after the decimal point)
    • DATE FUNCTIONS
    • Ex:
      Mysql>select curdate();
      2009-12-29
      Mysql>select curtime();
      13:04:21
      Mysql>select now();
      2009-12-29 13:05:12
    • Mysql>select monthname(‘2009-10-09’);
      october
      Mysql>select month(‘2009-10-09’);
      10 (returns the month in numeric format)
      Mysql>select minute(‘13:05:12’);
      5
      Mysql>select hour(‘13:05:12’);
      13
    • Mysql>select dayname(‘2010-01-01’);
      Friday
      Mysql>select dayofmonth(‘2010-01-01’);
      1 (returns the day in the range 1 to 31)
      Mysql>select dayofweek(‘2010-21-01’):
      5 (returns the day in the range 1 to 7)
    • Mysql>select datediff(‘2009-1-1’,’2009-10-10’);
      83
      (returns the difference between the dates in days)
      Mysql>select date_add(‘2009-12-29’,interval 3 day);
      2010-01-01
      (returns the new date formed after adding the number of days mentioned in the interval)
    • 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.
    • Visit more self help tutorials
      Pick a tutorial of your choice and browse through it at your own pace.
      The tutorials section is free, self-guiding and will not involve any additional support.
      Visit us at www.dataminingtools.net