0% found this document useful (0 votes)
63 views11 pages

Built in Function Praticals

Uploaded by

mymovies1241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views11 pages

Built in Function Praticals

Uploaded by

mymovies1241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Last login: Mon Feb 5 08:07:27 on console

/dev/fd/12:18: command not found: compdef


(base) shirishpatil@shirishs-MacBook-Air ~ % mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use collage;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_collage |
+-------------------+
| arith |
| emp |
| student |
+-------------------+
3 rows in set (0.00 sec)

mysql> select * from emp;


+----+---------+------------+--------+------------+
| id | name | dept | salary | doj |
+----+---------+------------+--------+------------+
| 1 | Harry | IT | 97000 | 2019-04-12 |
| 2 | Mac | HR | 55000 | 2018-06-12 |
| 3 | Rox | Support | 97000 | 2015-10-07 |
| 4 | Shree | IT | 99000 | 2019-09-01 |
| 5 | seema | HR | 64000 | 2020-08-23 |
| 6 | Roshani | IT | 54000 | 2018-09-10 |
| 7 | Roshan | Support | 34000 | 2019-07-11 |
| 8 | Meera | IT | 55000 | 2021-09-11 |
| 9 | Piyush | IT | 25000 | 2022-10-11 |
| 10 | Manish | Production | 35000 | 2023-07-13 |
| 11 | Priya | IT | 43000 | 2018-08-23 |
| 12 | Nilam | HR | 38000 | 2017-06-11 |
+----+---------+------------+--------+------------+
12 rows in set (0.02 sec)

mysql> select concat('Tech','Setu');


+-----------------------+
| concat('Tech','Setu') |
+-----------------------+
| TechSetu |
+-----------------------+
1 row in set (0.01 sec)

mysql> select concat('Tech','Setu') as result;


+----------+
| result |
+----------+
| TechSetu |
+----------+
1 row in set (0.00 sec)

mysql> select concat('Tech','-','Setu') as result;


+-----------+
| result |
+-----------+
| Tech-Setu |
+-----------+
1 row in set (0.00 sec)

mysql> select name,dept,concat(name,'-',dept) as name_dept from emp;


+---------+------------+-------------------+
| name | dept | name_dept |
+---------+------------+-------------------+
| Harry | IT | Harry-IT |
| Mac | HR | Mac-HR |
| Rox | Support | Rox-Support |
| Shree | IT | Shree-IT |
| seema | HR | seema-HR |
| Roshani | IT | Roshani-IT |
| Roshan | Support | Roshan-Support |
| Meera | IT | Meera-IT |
| Piyush | IT | Piyush-IT |
| Manish | Production | Manish-Production |
| Priya | IT | Priya-IT |
| Nilam | HR | Nilam-HR |
+---------+------------+-------------------+
12 rows in set (0.00 sec)

mysql> select length('techsetu') as len;


+-----+
| len |
+-----+
| 8 |
+-----+
1 row in set (0.00 sec)

mysql> select* from emp;


+----+---------+------------+--------+------------+
| id | name | dept | salary | doj |
+----+---------+------------+--------+------------+
| 1 | Harry | IT | 97000 | 2019-04-12 |
| 2 | Mac | HR | 55000 | 2018-06-12 |
| 3 | Rox | Support | 97000 | 2015-10-07 |
| 4 | Shree | IT | 99000 | 2019-09-01 |
| 5 | seema | HR | 64000 | 2020-08-23 |
| 6 | Roshani | IT | 54000 | 2018-09-10 |
| 7 | Roshan | Support | 34000 | 2019-07-11 |
| 8 | Meera | IT | 55000 | 2021-09-11 |
| 9 | Piyush | IT | 25000 | 2022-10-11 |
| 10 | Manish | Production | 35000 | 2023-07-13 |
| 11 | Priya | IT | 43000 | 2018-08-23 |
| 12 | Nilam | HR | 38000 | 2017-06-11 |
+----+---------+------------+--------+------------+
12 rows in set (0.00 sec)

mysql> select name,length(name) as len_name from emp;


+---------+----------+
| name | len_name |
+---------+----------+
| Harry | 5 |
| Mac | 3 |
| Rox | 3 |
| Shree | 5 |
| seema | 5 |
| Roshani | 7 |
| Roshan | 6 |
| Meera | 5 |
| Piyush | 6 |
| Manish | 6 |
| Priya | 5 |
| Nilam | 5 |
+---------+----------+
12 rows in set (0.00 sec)

mysql> select substr('TechSetu',5,4) as result;


+--------+
| result |
+--------+
| Setu |
+--------+
1 row in set (0.00 sec)

mysql> select name,upper(name) as up_name,dept,lower(dept) as low_dept from emp;


+---------+---------+------------+------------+
| name | up_name | dept | low_dept |
+---------+---------+------------+------------+
| Harry | HARRY | IT | it |
| Mac | MAC | HR | hr |
| Rox | ROX | Support | support |
| Shree | SHREE | IT | it |
| seema | SEEMA | HR | hr |
| Roshani | ROSHANI | IT | it |
| Roshan | ROSHAN | Support | support |
| Meera | MEERA | IT | it |
| Piyush | PIYUSH | IT | it |
| Manish | MANISH | Production | production |
| Priya | PRIYA | IT | it |
| Nilam | NILAM | HR | hr |
+---------+---------+------------+------------+
12 rows in set (0.01 sec)

mysql> select replace("Good Evening",'evening','night') as result;


+--------------+
| result |
+--------------+
| Good Evening |
+--------------+
1 row in set (0.00 sec)

mysql> select replace("Good Evening",'Evening','night') as result;


+------------+
| result |
+------------+
| Good night |
+------------+
1 row in set (0.01 sec)

mysql> select now() as current_dt;


+---------------------+
| current_dt |
+---------------------+
| 2024-02-05 19:17:19 |
+---------------------+
1 row in set (0.00 sec)

mysql> select sysdate() as current_dt;


+---------------------+
| current_dt |
+---------------------+
| 2024-02-05 19:17:33 |
+---------------------+
1 row in set (0.00 sec)

mysql> select curdate() as cur_date;


+------------+
| cur_date |
+------------+
| 2024-02-05 |
+------------+
1 row in set (0.00 sec)

mysql> select curtime() as cur_time;


+----------+
| cur_time |
+----------+
| 19:19:35 |
+----------+
1 row in set (0.00 sec)

mysql> select year(now()) as year;


+------+
| year |
+------+
| 2024 |
+------+
1 row in set (0.00 sec)

mysql> select month(now()) as month;


+-------+
| month |
+-------+
| 2 |
+-------+
1 row in set (0.00 sec)

mysql> select day(now()) as day;


+------+
| day |
+------+
| 5 |
+------+
1 row in set (0.00 sec)

mysql> select hour(now()) as hrs;


+------+
| hrs |
+------+
| 19 |
+------+
1 row in set (0.00 sec)

mysql> select minute(now()) as minute;


+--------+
| minute |
+--------+
| 28 |
+--------+
1 row in set (0.00 sec)

mysql> select second(now()) as seconds;


+---------+
| seconds |
+---------+
| 13 |
+---------+
1 row in set (0.00 sec)

mysql> select datediff('2024-01-01','2023-01-01') as dt_diff;


+---------+
| dt_diff |
+---------+
| 365 |
+---------+
1 row in set (0.00 sec)

mysql> select * from emp;


+----+---------+------------+--------+------------+
| id | name | dept | salary | doj |
+----+---------+------------+--------+------------+
| 1 | Harry | IT | 97000 | 2019-04-12 |
| 2 | Mac | HR | 55000 | 2018-06-12 |
| 3 | Rox | Support | 97000 | 2015-10-07 |
| 4 | Shree | IT | 99000 | 2019-09-01 |
| 5 | seema | HR | 64000 | 2020-08-23 |
| 6 | Roshani | IT | 54000 | 2018-09-10 |
| 7 | Roshan | Support | 34000 | 2019-07-11 |
| 8 | Meera | IT | 55000 | 2021-09-11 |
| 9 | Piyush | IT | 25000 | 2022-10-11 |
| 10 | Manish | Production | 35000 | 2023-07-13 |
| 11 | Priya | IT | 43000 | 2018-08-23 |
| 12 | Nilam | HR | 38000 | 2017-06-11 |
+----+---------+------------+--------+------------+
12 rows in set (0.00 sec)

mysql> select name,doj,datediff(now(),doj) as days from emp;


+---------+------------+------+
| name | doj | days |
+---------+------------+------+
| Harry | 2019-04-12 | 1760 |
| Mac | 2018-06-12 | 2064 |
| Rox | 2015-10-07 | 3043 |
| Shree | 2019-09-01 | 1618 |
| seema | 2020-08-23 | 1261 |
| Roshani | 2018-09-10 | 1974 |
| Roshan | 2019-07-11 | 1670 |
| Meera | 2021-09-11 | 877 |
| Piyush | 2022-10-11 | 482 |
| Manish | 2023-07-13 | 207 |
| Priya | 2018-08-23 | 1992 |
| Nilam | 2017-06-11 | 2430 |
+---------+------------+------+
12 rows in set (0.00 sec)

mysql> select name,doj,datediff(now(),doj)/365 as exp from emp;


+---------+------------+--------+
| name | doj | exp |
+---------+------------+--------+
| Harry | 2019-04-12 | 4.8219 |
| Mac | 2018-06-12 | 5.6548 |
| Rox | 2015-10-07 | 8.3370 |
| Shree | 2019-09-01 | 4.4329 |
| seema | 2020-08-23 | 3.4548 |
| Roshani | 2018-09-10 | 5.4082 |
| Roshan | 2019-07-11 | 4.5753 |
| Meera | 2021-09-11 | 2.4027 |
| Piyush | 2022-10-11 | 1.3205 |
| Manish | 2023-07-13 | 0.5671 |
| Priya | 2018-08-23 | 5.4575 |
| Nilam | 2017-06-11 | 6.6575 |
+---------+------------+--------+
12 rows in set (0.00 sec)

mysql> select sqrt(16) as result;


+--------+
| result |
+--------+
| 4 |
+--------+
1 row in set (0.01 sec)

mysql> select power(2,3) as result;


+--------+
| result |
+--------+
| 8 |
+--------+
1 row in set (0.00 sec)

mysql> select pow(2,3) as result;


+--------+
| result |
+--------+
| 8 |
+--------+
1 row in set (0.00 sec)

mysql> select round(15.3) as result;


+--------+
| result |
+--------+
| 15 |
+--------+
1 row in set (0.00 sec)

mysql> select round(15.5) as result;


+--------+
| result |
+--------+
| 16 |
+--------+
1 row in set (0.00 sec)

mysql> select round(15.7) as result;


+--------+
| result |
+--------+
| 16 |
+--------+
1 row in set (0.00 sec)

mysql> select floor(15.2) as result;


+--------+
| result |
+--------+
| 15 |
+--------+
1 row in set (0.00 sec)

mysql> select floor(15.5) as result;


+--------+
| result |
+--------+
| 15 |
+--------+
1 row in set (0.00 sec)

mysql> select floor(15.8) as result;


+--------+
| result |
+--------+
| 15 |
+--------+
1 row in set (0.01 sec)

mysql> select ceil(15.2) as result;


+--------+
| result |
+--------+
| 16 |
+--------+
1 row in set (0.00 sec)

mysql> select ceil(15.8) as result;


+--------+
| result |
+--------+
| 16 |
+--------+
1 row in set (0.00 sec)

mysql> select ceil(15.5) as result;


+--------+
| result |
+--------+
| 16 |
+--------+
1 row in set (0.00 sec)

mysql> select name,doj,floor(datediff(now(),doj)/365) as exp from emp;


+---------+------------+------+
| name | doj | exp |
+---------+------------+------+
| Harry | 2019-04-12 | 4 |
| Mac | 2018-06-12 | 5 |
| Rox | 2015-10-07 | 8 |
| Shree | 2019-09-01 | 4 |
| seema | 2020-08-23 | 3 |
| Roshani | 2018-09-10 | 5 |
| Roshan | 2019-07-11 | 4 |
| Meera | 2021-09-11 | 2 |
| Piyush | 2022-10-11 | 1 |
| Manish | 2023-07-13 | 0 |
| Priya | 2018-08-23 | 5 |
| Nilam | 2017-06-11 | 6 |
+---------+------------+------+
12 rows in set (0.00 sec)

mysql> select * from emp;


+----+---------+------------+--------+------------+
| id | name | dept | salary | doj |
+----+---------+------------+--------+------------+
| 1 | Harry | IT | 97000 | 2019-04-12 |
| 2 | Mac | HR | 55000 | 2018-06-12 |
| 3 | Rox | Support | 97000 | 2015-10-07 |
| 4 | Shree | IT | 99000 | 2019-09-01 |
| 5 | seema | HR | 64000 | 2020-08-23 |
| 6 | Roshani | IT | 54000 | 2018-09-10 |
| 7 | Roshan | Support | 34000 | 2019-07-11 |
| 8 | Meera | IT | 55000 | 2021-09-11 |
| 9 | Piyush | IT | 25000 | 2022-10-11 |
| 10 | Manish | Production | 35000 | 2023-07-13 |
| 11 | Priya | IT | 43000 | 2018-08-23 |
| 12 | Nilam | HR | 38000 | 2017-06-11 |
+----+---------+------------+--------+------------+
12 rows in set (0.00 sec)

mysql> select sum(salary) as tot_payable from emp;


+-------------+
| tot_payable |
+-------------+
| 696000 |
+-------------+
1 row in set (0.01 sec)

mysql> select count(dept) from emp;


+-------------+
| count(dept) |
+-------------+
| 12 |
+-------------+
1 row in set (0.00 sec)

mysql> select count(*) as ct from emp;


+----+
| ct |
+----+
| 12 |
+----+
1 row in set (0.01 sec)

mysql> desc emp;


+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | varchar(50) | YES | | NULL | |
| dept | varchar(50) | YES | | NULL | |
| salary | float | YES | | NULL | |
| doj | date | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
5 rows in set (0.03 sec)

mysql> insert into emp(name,salary,doj)values('Amit',45000,now());


Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> select * from emp;


+----+---------+------------+--------+------------+
| id | name | dept | salary | doj |
+----+---------+------------+--------+------------+
| 1 | Harry | IT | 97000 | 2019-04-12 |
| 2 | Mac | HR | 55000 | 2018-06-12 |
| 3 | Rox | Support | 97000 | 2015-10-07 |
| 4 | Shree | IT | 99000 | 2019-09-01 |
| 5 | seema | HR | 64000 | 2020-08-23 |
| 6 | Roshani | IT | 54000 | 2018-09-10 |
| 7 | Roshan | Support | 34000 | 2019-07-11 |
| 8 | Meera | IT | 55000 | 2021-09-11 |
| 9 | Piyush | IT | 25000 | 2022-10-11 |
| 10 | Manish | Production | 35000 | 2023-07-13 |
| 11 | Priya | IT | 43000 | 2018-08-23 |
| 12 | Nilam | HR | 38000 | 2017-06-11 |
| 13 | Amit | NULL | 45000 | 2024-02-05 |
+----+---------+------------+--------+------------+
13 rows in set (0.00 sec)

mysql> select count(*) from emp;


+----------+
| count(*) |
+----------+
| 13 |
+----------+
1 row in set (0.00 sec)

mysql> select count(dept) from emp;


+-------------+
| count(dept) |
+-------------+
| 12 |
+-------------+
1 row in set (0.00 sec)

mysql> select avg(salary) from emp;


+-------------+
| avg(salary) |
+-------------+
| 57000 |
+-------------+
1 row in set (0.00 sec)

mysql> select max(salary) from emp;


+-------------+
| max(salary) |
+-------------+
| 99000 |
+-------------+
1 row in set (0.00 sec)

mysql> select min(salary) from emp;


+-------------+
| min(salary) |
+-------------+
| 25000 |
+-------------+
1 row in set (0.00 sec)

mysql> select max(dept) from emp;


+-----------+
| max(dept) |
+-----------+
| Support |
+-----------+
1 row in set (0.00 sec)

mysql> select min(dept) from emp;


+-----------+
| min(dept) |
+-----------+
| HR |
+-----------+
1 row in set (0.00 sec)

mysql> select avg(dept) from emp;


+-----------+
| avg(dept) |
+-----------+
| 0 |
+-----------+
1 row in set, 3 warnings (0.00 sec)

mysql> select min(doj) from emp;


+------------+
| min(doj) |
+------------+
| 2015-10-07 |
+------------+
1 row in set (0.00 sec)

mysql> select max(doj) from emp;


+------------+
| max(doj) |
+------------+
| 2024-02-05 |
+------------+
1 row in set (0.00 sec)

mysql> select max(doj) from emp;

You might also like