You are on page 1of 7

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 1
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

1.


2.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 2
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

All mathematical functions return NULL in the event of an error.

SELECT POW(2,2); 4
SELECT POWER(2,-2); 0.25

SELECT POW(-2,-2); 0.25

SELECT POW(1.5,2); 2.25


Query Example:-

(i) Write SQL Query to display name and square of their salary from emp table who works in “Research”
Department.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 3
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

(ii) Write SQL Query to display square root of all salary from emp table.

SELECT ROUND(1.58); 2

SELECT ROUND(2.4) 2

SELECT ROUND(-1.58); -2

SELECT ROUND(-2.6); -3

SELECT ROUND(-1.23); -1

SELECT ROUND(1.298, 1); 1.3

SELECT ROUND(1.298, 2); 1.30

SELECT ROUND(1.298, 0); 1

SELECT ROUND(23.298, -1); 20

When -1 rounding nearest 10


When -2 rounding nearest 100
When -3 rounding nearest 1000

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 4
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

When -4 rounding nearest 10000

SELECT ROUND(45846.298, -1); 45850


SELECT ROUND(45846.298, -2); 45800
SELECT ROUND(45846.298, -3); 46000
SELECT ROUND(45846.298, -4); 50000
SELECT ROUND (45.923, 0); 46
SELECT ROUND(45.923,-1); 50
SELECT ROUND(45.923,-2); 0
SELECT ROUND(55.923,-2); 100
SELECT ROUND(146.923,-2); 100
SELECT ROUND(156.923,-2); 200
Query Example:-

(i) Write SQL Query to display salary of all employees rounds to nearest thousand.

(ii) Write SQL Query to display salary rounds to having integer only .

OR

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 5
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

SELECT MOD(234, 10); 4

SELECT 253 % 7; 1

SELECT MOD(29,9); 2

SELECT 29 MOD 9; 2

SELECT MOD(34.5,3); 1.5

(MOD() also works on values


that have a fractional part
and returns the exact
remainder after division:)

SELECT MOD(5.5,2); 1.5

SELECT MOD(6,2); 0

Query Example 1:- display the remainder of the ratio of salary to commission for all employees whose job title is
salesman.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 6
Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

ABS(X) Returns the absolute value of X.


mysql> SELECT ABS(2); -> 2
mysql> SELECT ABS(-32); -> 32

CEILING(X), CEIL Returns the smallest integer value not less than X.
(X) mysql> SELECT CEILING(1.23); -> 2
mysql> SELECT CEIL(-1.23); -> -1

FLOOR(X) Returns the largest integer value not greater than X.


mysql> SELECT FLOOR(1.23); -> 1
mysql> SELECT FLOOR(-1.23); -> -2

SQRT(X) Returns the square root of a non-negative number X.

mysql> SELECT SQRT(4); -> 2


mysql> SELECT SQRT(20); -> 4.4721359549996
mysql> SELECT SQRT(-16); -> NULL

TRUNCATE(X,D) Returns the number X, truncated to D decimal places. If D is 0, the


result has no decimal point or fractional part. D can be negative to
cause D digits left of the decimal point of the value X to become zero.

mysql> SELECT TRUNCATE(1.223,1); -> 1.2


mysql> SELECT TRUNCATE(1.999,1); -> 1.9
mysql> SELECT TRUNCATE(1.999,0); -> 1
mysql> SELECT TRUNCATE(-1.999,1); -> -1.9
mysql> SELECT TRUNCATE(122,-2); -> 100
mysql> SELECT TRUNCATE(10.28*100,0); -> 1028

All numbers are rounded toward zero.

Video of this topic uploaded in YouTube Channel “Learn with AKJoshi” Watch,Subscribe and Like

Page 7

You might also like