0% found this document useful (0 votes)
16 views

Mysql 25 Queries

c.s stuff

Uploaded by

yikidow927
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Mysql 25 Queries

c.s stuff

Uploaded by

yikidow927
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

mysql> select* from emp;

+-------+-----------+-----------+------+------------+----------+---------+--------+

| empno | ename | job | mgr | hiredate | sal | comm | deptno |

+-------+-----------+-----------+------+------------+----------+---------+--------+

| 8369 | SMITH | CLERK | 8902 | 1990-12-18 | 10000.00 | NULL | 20 |

| 8499 | ANYA | SALESMAN | 8698 | 1991-02-20 | 1600.00 | 300.00 | 30 |

| 8521 | SETH | SALESMAN | 8698 | 1991-02-22 | 1250.00 | 500.00 | 30 |

| 8566 | MAHADEVAN | MANAGER | 8839 | 1991-04-02 | 2985.00 | NULL | 20 |

| 8654 | MOMIN | SALESMAN | 8698 | 1991-09-28 | 1250.00 | 1400.00 | 30 |

| 8698 | BINA | MANAGER | 8839 | 1991-05-01 | 2850.00 | NULL | 30 |

| 8839 | AMIR | PRESIDENT | NULL | 1991-11-18 | 5000.00 | NULL | 10 |

| 8844 | KULDEEP | SALESMAN | 8698 | 1991-09-08 | 1500.00 | 0.00 | 30 |

| 8882 | SHIVANSH | MANAGER | 8839 | 1991-06-09 | 2450.00 | NULL | 10 |

| 8886 | ANOOP | CLERK | 8888 | 1993-01-12 | 1100.00 | NULL | 20 |

| 8888 | SCOTT | ANALYST | 8566 | 1992-12-09 | 3000.00 | NULL | 20 |

| 8900 | JATIN | CLERK | 8698 | 1991-12-03 | 950.00 | NULL | 30 |

| 8902 | FAKIR | ANALYST | 8566 | 1991-12-03 | 3000.00 | NULL | 20 |

| 8934 | MITA | CLERK | 8882 | 1992-01-23 | 1300.00 | NULL | 10 |

+-------+-----------+-----------+------+------------+----------+---------+--------+

14 rows in set (0.00 sec)

mysql> select* from emp where job='clerk';

+-------+-------+-------+------+------------+----------+------+--------+

| empno | ename | job | mgr | hiredate | sal | comm | deptno |

+-------+-------+-------+------+------------+----------+------+--------+

| 8369 | SMITH | CLERK | 8902 | 1990-12-18 | 10000.00 | NULL | 20 |

| 8886 | ANOOP | CLERK | 8888 | 1993-01-12 | 1100.00 | NULL | 20 |

| 8900 | JATIN | CLERK | 8698 | 1991-12-03 | 950.00 | NULL | 30 |

| 8934 | MITA | CLERK | 8882 | 1992-01-23 | 1300.00 | NULL | 10 |

+-------+-------+-------+------+------------+----------+------+--------+
4 rows in set (0.00 sec)

mysql> select* from emp where job=!'clerk';

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near '=!'clerk'' at line 1

mysql> select* from emp where job!='clerk';

+-------+-----------+-----------+------+------------+---------+---------+--------+

| empno | ename | job | mgr | hiredate | sal | comm | deptno |

+-------+-----------+-----------+------+------------+---------+---------+--------+

| 8499 | ANYA | SALESMAN | 8698 | 1991-02-20 | 1600.00 | 300.00 | 30 |

| 8521 | SETH | SALESMAN | 8698 | 1991-02-22 | 1250.00 | 500.00 | 30 |

| 8566 | MAHADEVAN | MANAGER | 8839 | 1991-04-02 | 2985.00 | NULL | 20 |

| 8654 | MOMIN | SALESMAN | 8698 | 1991-09-28 | 1250.00 | 1400.00 | 30 |

| 8698 | BINA | MANAGER | 8839 | 1991-05-01 | 2850.00 | NULL | 30 |

| 8839 | AMIR | PRESIDENT | NULL | 1991-11-18 | 5000.00 | NULL | 10 |

| 8844 | KULDEEP | SALESMAN | 8698 | 1991-09-08 | 1500.00 | 0.00 | 30 |

| 8882 | SHIVANSH | MANAGER | 8839 | 1991-06-09 | 2450.00 | NULL | 10 |

| 8888 | SCOTT | ANALYST | 8566 | 1992-12-09 | 3000.00 | NULL | 20 |

| 8902 | FAKIR | ANALYST | 8566 | 1991-12-03 | 3000.00 | NULL | 20 |

+-------+-----------+-----------+------+------------+---------+---------+--------+

10 rows in set (0.00 sec)

mysql> select* from emp where ename like'_a%';

+-------+-----------+---------+------+------------+---------+------+--------+

| empno | ename | job | mgr | hiredate | sal | comm | deptno |

+-------+-----------+---------+------+------------+---------+------+--------+

| 8566 | MAHADEVAN | MANAGER | 8839 | 1991-04-02 | 2985.00 | NULL | 20 |

| 8900 | JATIN | CLERK | 8698 | 1991-12-03 | 950.00 | NULL | 30 |

| 8902 | FAKIR | ANALYST | 8566 | 1991-12-03 | 3000.00 | NULL | 20 |

+-------+-----------+---------+------+------------+---------+------+--------+

3 rows in set (0.00 sec)


mysql> select ename,job,sal,sal*15 as Bonus from emp;

+-----------+-----------+----------+-----------+

| ename | job | sal | Bonus |

+-----------+-----------+----------+-----------+

| SMITH | CLERK | 10000.00 | 150000.00 |

| ANYA | SALESMAN | 1600.00 | 24000.00 |

| SETH | SALESMAN | 1250.00 | 18750.00 |

| MAHADEVAN | MANAGER | 2985.00 | 44775.00 |

| MOMIN | SALESMAN | 1250.00 | 18750.00 |

| BINA | MANAGER | 2850.00 | 42750.00 |

| AMIR | PRESIDENT | 5000.00 | 75000.00 |

| KULDEEP | SALESMAN | 1500.00 | 22500.00 |

| SHIVANSH | MANAGER | 2450.00 | 36750.00 |

| ANOOP | CLERK | 1100.00 | 16500.00 |

| SCOTT | ANALYST | 3000.00 | 45000.00 |

| JATIN | CLERK | 950.00 | 14250.00 |

| FAKIR | ANALYST | 3000.00 | 45000.00 |

| MITA | CLERK | 1300.00 | 19500.00 |

+-----------+-----------+----------+-----------+

14 rows in set (0.00 sec)

mysql> select distinct job from emp;

+-----------+

| job |

+-----------+

| CLERK |

| SALESMAN |

| MANAGER |

| PRESIDENT |

| ANALYST |
+-----------+

5 rows in set (0.00 sec)

mysql> select count(distinct job) from emp;

+---------------------+

| count(distinct job) |

+---------------------+

| 5|

+---------------------+

1 row in set (0.00 sec)

mysql> select count(*) from emp;

+----------+

| count(*) |

+----------+

| 14 |

+----------+

1 row in set (0.00 sec)

mysql> select max(sal),min(sal),avg(sal),sum(sal),job from emp where job='clerk';

+----------+----------+-------------+----------+-------+

| max(sal) | min(sal) | avg(sal) | sum(sal) | job |

+----------+----------+-------------+----------+-------+

| 10000.00 | 950.00 | 3337.500000 | 13350.00 | CLERK |

+----------+----------+-------------+----------+-------+

1 row in set (0.00 sec)

mysql> select* from emp group by having count(*)>3;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'having count(*)>3' at line 1

mysql> select* from emp group by having count(*) >3;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'having count(*) >3' at line 1

mysql> select * from emp group by job having count(*) >3;

+-------+-------+----------+------+------------+----------+--------+--------+

| empno | ename | job | mgr | hiredate | sal | comm | deptno |

+-------+-------+----------+------+------------+----------+--------+--------+

| 8369 | SMITH | CLERK | 8902 | 1990-12-18 | 10000.00 | NULL | 20 |

| 8499 | ANYA | SALESMAN | 8698 | 1991-02-20 | 1600.00 | 300.00 | 30 |

+-------+-------+----------+------+------------+----------+--------+--------+

2 rows in set (0.00 sec)

mysql> select* from dept;

+--------+------------+

| deptno | dname |

+--------+------------+

| 10 | Marketing |

| 20 | Sourcing |

| 30 | Production |

| 40 | Management |

| 50 | Overseas |

+--------+------------+

5 rows in set (0.01 sec)

mysql> select e.empno,e.name,e.job,e.sal,d.dname from emp e,dept d where e.deptno=d.deptno;

ERROR 1054 (42S22): Unknown column 'e.name' in 'field list'

mysql> select e.empno,e.ename,e.job,e.sal,d.dname from emp e,dept d where e.deptno=d.deptno;

+-------+-----------+-----------+----------+------------+

| empno | ename | job | sal | dname |

+-------+-----------+-----------+----------+------------+

| 8369 | SMITH | CLERK | 10000.00 | Sourcing |

| 8499 | ANYA | SALESMAN | 1600.00 | Production |


| 8521 | SETH | SALESMAN | 1250.00 | Production |

| 8566 | MAHADEVAN | MANAGER | 2985.00 | Sourcing |

| 8654 | MOMIN | SALESMAN | 1250.00 | Production |

| 8698 | BINA | MANAGER | 2850.00 | Production |

| 8839 | AMIR | PRESIDENT | 5000.00 | Marketing |

| 8844 | KULDEEP | SALESMAN | 1500.00 | Production |

| 8882 | SHIVANSH | MANAGER | 2450.00 | Marketing |

| 8886 | ANOOP | CLERK | 1100.00 | Sourcing |

| 8888 | SCOTT | ANALYST | 3000.00 | Sourcing |

| 8900 | JATIN | CLERK | 950.00 | Production |

| 8902 | FAKIR | ANALYST | 3000.00 | Sourcing |

| 8934 | MITA | CLERK | 1300.00 | Marketing |

+-------+-----------+-----------+----------+------------+

14 rows in set (0.00 sec)

mysql> select char(65) from dual;

+----------+

| char(65) |

+----------+

|A |

+----------+

1 row in set (0.00 sec)

mysql> select concat(ename,job) from emp;

+-------------------+

| concat(ename,job) |

+-------------------+

| SMITHCLERK |

| ANYASALESMAN |

| SETHSALESMAN |

| MAHADEVANMANAGER |
| MOMINSALESMAN |

| BINAMANAGER |

| AMIRPRESIDENT |

| KULDEEPSALESMAN |

| SHIVANSHMANAGER |

| ANOOPCLERK |

| SCOTTANALYST |

| JATINCLERK |

| FAKIRANALYST |

| MITACLERK |

+-------------------+

14 rows in set (0.00 sec)

mysql> select concat('riddhima','murarka') from dual;

+------------------------------+

| concat('riddhima','murarka') |

+------------------------------+

| riddhimamurarka |

+------------------------------+

1 row in set (0.00 sec)

mysql> select ucase(ename) from emp;

+--------------+

| ucase(ename) |

+--------------+

| SMITH |

| ANYA |

| SETH |

| MAHADEVAN |

| MOMIN |

| BINA |
| AMIR |

| KULDEEP |

| SHIVANSH |

| ANOOP |

| SCOTT |

| JATIN |

| FAKIR |

| MITA |

+--------------+

14 rows in set (0.00 sec)

mysql> select trim(" riddhima ") from dual;

+---------------------------------+

| trim(" riddhima ") |

+---------------------------------+

| riddhima |

+---------------------------------+

1 row in set (0.00 sec)

mysql> select length(ename) from emp;

+---------------+

| length(ename) |

+---------------+

| 5|

| 4|

| 4|

| 9|

| 5|

| 4|

| 4|

| 7|
| 8|

| 5|

| 5|

| 5|

| 5|

| 4|

+---------------+

14 rows in set (0.00 sec)

mysql> select truncate(12.56789,2) from dual;

+----------------------+

| truncate(12.56789,2) |

+----------------------+

| 12.56 |

+----------------------+

1 row in set (0.00 sec)

mysql> select now() from dual;

+---------------------+

| now() |

+---------------------+

| 2023-12-11 08:58:02 |

+---------------------+

1 row in set (0.00 sec)

mysql> select date('2023-11-03') from dual;

+--------------------+

| date('2023-11-03') |

+--------------------+

| 2023-11-03 |

+--------------------+
1 row in set (0.00 sec)

mysql>

You might also like