import sqlalchemy
sqlalchemy.create_engine("mysql+mysqldb://root:*****@localhost:3306/oracle_emp")
Engine(mysql+mysqldb://root:***@localhost:3306/oracle_emp)
%load_ext sql
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.QVLO2T66WEPI7JZ63PS3HMOHFEY472BC.gfortran-win_amd64.dll
  stacklevel=1)
%sql "mysql+mysqldb://root:*****@localhost:3306/oracle_emp"
%%sql
select * from emp e where (datediff(curdate(),hiredate)/365)>(select (datediff(curdate(),hiredate)/365) from emp f where f.empno=e.mgr )
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
6 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
%%sql
select * from emp e where e.deptno=20 and e.job in (select f.job from emp f where f.deptno=10) ;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
%%sql
select * from emp e where e.sal in(select f.sal from emp f where f.ename like "FORD" or f.ename like "SMITH") and e.ename not like "FORD" and e.ename not like "Smith" order by sal desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
%%sql
select * from emp e where e.job like (select f.job from emp f where f.ename like "Miller") 
or e.sal >(select g.sal from emp g where g.ename="Allen")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
10 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select * from emp e where e.sal > (select max(f.sal+f.comm)  from emp f where f.job like "salesman")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select e.* from emp e,dept d where (datediff(curdate(),e.hiredate)/365) >(select (datediff(curdate(),f.hiredate)/365) 
                                                                    from emp f where f.ename like "Blake")
and e.deptno=d.deptno and d.loc like "chicago" 
union
select e.* from emp e,dept d where (datediff(curdate(),e.hiredate)/365) >(select (datediff(curdate(),f.hiredate)/365) 
                                                                    from emp f where f.ename like "Blake")
and e.deptno=d.deptno and d.loc like "boston"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
%%sql
select * from emp e,salgrade g,dept d where e.sal between g.losal and g.hisal and g.grade in(3,4) and e.deptno=d.deptno
and d.dname in("Accounting","Research") and e.sal>(select f.sal from emp f where f.ename="Allen") and (datediff(curdate(),e.hiredate)/365)>
(select (datediff(curdate(),f.hiredate)/365) 
                                                                    from emp f where f.ename like "Blake") order by e.hiredate
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | grade | losal | hisal | deptno_1 | dname | loc | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 4 | 2001 | 3000 | 20 | RESEARCH | DALLAS | 
%%sql
select * from emp
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
create table emp1 (sal int4)
%%sql
insert into emp1 select sal from emp;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
[]
%%sql
select * from emp1
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| sal | 
|---|
| 800 | 
| 1600 | 
| 1250 | 
| 2975 | 
| 1250 | 
| 2850 | 
| 2450 | 
| 3000 | 
| 5000 | 
| 1500 | 
| 1100 | 
| 950 | 
| 3000 | 
| 1300 | 
%%sql
CREATE TABLE emp2 (sal int4)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
[]
%%sql 
insert into emp2 select (3/4)*sal from emp e where e.job like "Manager"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
[]
%%sql
select * from emp2
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| sal | 
|---|
| 2231 | 
| 2138 | 
| 1838 | 
%%sql
create table emp3 (sal int4)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
[]
%%sql 
insert into emp3 select e.sal from emp e,dept d where (datediff(curdate(),e.hiredate)/365) >38 and e.deptno=d.deptno and d.dname like "Sales"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
6 rows affected.
[]
%%sql
select * from emp3
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
6 rows affected.
| sal | 
|---|
| 1600 | 
| 1250 | 
| 1250 | 
| 2850 | 
| 1500 | 
| 950 | 
%%sql
create table emp4(
  empno    int4,
  ename    varchar(10),
  job      varchar(9),
  mgr      int4,
  hiredate date,
  sal      decimal(7,2),
  comm     decimal(7,2),
  deptno   int2,
    constraint pk_emp primary key (empno)
)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
[]
%%sql
insert into emp4 select e.* from emp e,salgrade g 
where e.sal between g.losal and g.hisal and g.grade=2
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
[]
%%sql
select * from emp4
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
create table emp5 (empno    int4,
  ename    varchar(10),
  job      varchar(9),
  mgr      int4,
  hiredate date,
  sal      decimal(7,2),
  comm     decimal(7,2),
  deptno   int2,
    constraint pk_emp primary key (empno))
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
[]
%%sql
insert into emp5 select e.* from emp e,salgrade g,dept d where 1989=extract(year from e.hiredate)
and e.sal between g.losal and g.hisal and g.grade in(2,3) and e.deptno=d.deptno and d.dname in ("Sales","Operations")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
[]
%%sql
select * from emp5
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|
%%sql
select distinct(e1.job) from emp e1,emp e2 where e1.deptno=10 and e2.deptno=20 and e1.job<>e2.job
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| job | 
|---|
| MANAGER | 
| PRESIDENT | 
| CLERK | 
%%sql
select e1.ename from emp4 e1,emp5 e2 where e1.ename<>e2.ename
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
| ename | 
|---|
%%sql 
select max(sal) from emp 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| max(sal) | 
|---|
| 5000.00 | 
%%sql
select * from emp where sal in(select max(e.sal) from emp e)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
%%sql
select max(e.sal) from emp e,dept d where e.deptno=d.deptno and d.dname="Sales"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| max(e.sal) | 
|---|
| 2850.00 | 
%%sql
select * from emp e,salgrade g,dept d where e.sal between g.losal and g.hisal and g.grade=3 and e.deptno=d.deptno and d.loc="chicago"
order by e.hiredate desc limit 1
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | grade | losal | hisal | deptno_1 | dname | loc | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 3 | 1401 | 2000 | 30 | SALES | CHICAGO | 
%%sql
select * from emp e1 where e1.hiredate<(select max(e.hiredate) from emp e where e.mgr in
                                        (select e2.empno from emp e2 where e2.ename="King"))
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
%%sql
select e.* from emp e,dept d,salgrade g where e.deptno=d.deptno and d.loc="new york" 
and
e.sal between g.losal and g.hisal and g.grade between 3 and 5 and
e.job<>"President"  and e.sal >(select max(e1.sal) from emp e1,dept d1 where e1.deptno=d1.deptno and 
                                d1.loc="Chicago" and e1.mgr<>(select e3.empno from emp e3 where e3.job="President" ) group by e1.deptno )
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
%%sql
select * from emp e where 1981=extract( year from e.hiredate) order by e.hiredate asc limit 1
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
%%sql
select * from emp e where 1981=extract(year from e.hiredate) and e.job = (select e1.job from emp e1 where 1981=extract( year from e1.hiredate) order by e1.hiredate asc limit 1)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
4 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
%%sql 
select * from emp e where e.hiredate =(select min(e1.hiredate) from emp e1,salgrade g1 where 
                                       e1.sal between g1.losal and g1.hisal and g1.grade > 3 
                                       and e1.mgr =(select e2.empno from emp e2 where e2.ename="King"))
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
%%sql
select sum(e.sal) from emp e where e.job="Manager"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| sum(e.sal) | 
|---|
| 8275.00 | 
%%sql
select e.job,sum(e.sal)*12 as AnnualSal from emp e where 1981=extract(year from e.hiredate) group by e.job
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| job | AnnualSal | 
|---|---|
| SALESMAN | 67200.00 | 
| MANAGER | 99300.00 | 
| PRESIDENT | 60000.00 | 
| CLERK | 11400.00 | 
| ANALYST | 36000.00 | 
%%sql
select sum(e.sal) from emp e,salgrade g where e.sal between g.losal and g.hisal and g.grade=3
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| sum(e.sal) | 
|---|
| 3100.00 | 
%%sql
select avg(e.sal) from emp e where e.job="clerk"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| avg(e.sal) | 
|---|
| 1037.500000 | 
%%sql
select * from emp e where e.deptno=20 and e.sal>(select avg(e1.sal) from emp e1 where e1.deptno=10)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select e.deptno,e.job,count(*) from emp e  group by e.job,e.deptno 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
9 rows affected.
| deptno | job | count(*) | 
|---|---|---|
| 20 | CLERK | 2 | 
| 30 | SALESMAN | 4 | 
| 20 | MANAGER | 1 | 
| 30 | MANAGER | 1 | 
| 10 | MANAGER | 1 | 
| 20 | ANALYST | 2 | 
| 10 | PRESIDENT | 1 | 
| 30 | CLERK | 1 | 
| 10 | CLERK | 1 | 
%%sql
select e.deptno,e.ename,e.job,count(*)  from emp e ,emp e1
       where  e.job="Manager" and e.empno=e1.mgr group by e.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| deptno | ename | job | count(*) | 
|---|---|---|---|
| 30 | BLAKE | MANAGER | 5 | 
| 20 | JONES | MANAGER | 2 | 
| 10 | CLARK | MANAGER | 1 | 
%%sql
select d.*,count(*) as CountOfEmployees from emp e,dept d where d.deptno=e.deptno and 1<(select count(*) from emp e1) group by d.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| deptno | dname | loc | CountOfEmployees | 
|---|---|---|---|
| 10 | ACCOUNTING | NEW YORK | 3 | 
| 20 | RESEARCH | DALLAS | 5 | 
| 30 | SALES | CHICAGO | 6 | 
%%sql
select g.grade,max(e.sal),count(*) from salgrade g ,emp e 
where e.sal between g.losal and g.hisal group by g.grade order by g.grade
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| grade | max(e.sal) | count(*) | 
|---|---|---|
| 1 | 1100.00 | 3 | 
| 2 | 1300.00 | 3 | 
| 3 | 1600.00 | 2 | 
| 4 | 3000.00 | 5 | 
| 5 | 5000.00 | 1 | 
%%sql
select d.deptno,d.dname,g.grade,count(*) as EmpCountInDept from emp e,dept d,salgrade g where 
e.sal between g.losal and g.hisal and e.deptno=d.deptno group by e.deptno
having e.deptno=(select e2.deptno from emp e2 where e2.job="clerk" group by e2.deptno having 1< count(*)) order by d.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| deptno | dname | grade | EmpCountInDept | 
|---|---|---|---|
| 20 | RESEARCH | 1 | 5 | 
%%sql
select d.*,count(*)  from dept d,emp e where d.deptno=e.deptno group by e.deptno order by count(*) desc limit 1
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| deptno | dname | loc | count(*) | 
|---|---|---|---|
| 30 | SALES | CHICAGO | 6 | 
%%sql
select * from emp e where e.mgr=(select e1.empno from emp e1 where e1.ename="jones")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp e where e.sal+(e.sal*20/100)>3000 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select e.*,d.dname from emp e,dept d where e.deptno=d.deptno  
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | dname | 
|---|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | ACCOUNTING | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | ACCOUNTING | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | ACCOUNTING | 
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | RESEARCH | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | RESEARCH | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | RESEARCH | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | RESEARCH | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | RESEARCH | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | SALES | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | SALES | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | SALES | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | SALES | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | SALES | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | SALES | 
%%sql
select e.*,d.dname from emp e,dept d where e.deptno=d.deptno and d.dname<>"Sales"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | dname | 
|---|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | ACCOUNTING | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | ACCOUNTING | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | ACCOUNTING | 
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | RESEARCH | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | RESEARCH | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | RESEARCH | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | RESEARCH | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | RESEARCH | 
%%sql
select e.ename,e.deptno,e.sal,e.comm,d.loc from emp e,dept d where e.sal between 2000 and 5000 and e.deptno=d.deptno and d.loc="Chicago"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| ename | deptno | sal | comm | loc | 
|---|---|---|---|---|
| BLAKE | 30 | 2850.00 | None | CHICAGO | 
%%sql
select * from emp e where e.sal>(select e2.sal from emp e2,emp e1 where e2.mgr=e1.empno and e2.job="Manager" group by e2.mgr ) 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select e.ename,g.grade,e.hiredate from emp e,salgrade g,dept d where e.deptno=d.deptno and d.deptno in (10,30) 
and e.sal between g.losal and g.hisal and g.grade not in (4)
and e.hiredate>1982-12-31
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
7 rows affected.
| ename | grade | hiredate | 
|---|---|---|
| JAMES | 1 | 1981-12-03 | 
| MARTIN | 2 | 1981-09-28 | 
| WARD | 2 | 1981-02-22 | 
| MILLER | 2 | 1982-01-23 | 
| TURNER | 3 | 1981-09-08 | 
| ALLEN | 3 | 1981-02-20 | 
| KING | 5 | 1981-11-07 | 
%%sql
select e.ename,e.job,d.dname,d.loc from emp e,dept d where e.job="Manager" and e.deptno=d.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| ename | job | dname | loc | 
|---|---|---|---|
| JONES | MANAGER | RESEARCH | DALLAS | 
| BLAKE | MANAGER | SALES | CHICAGO | 
| CLARK | MANAGER | ACCOUNTING | NEW YORK | 
%%sql
select e.ename,e2.ename as MgrName from emp e, emp e2 where 
e.mgr=(select e1.empno from emp e1 where e1.ename="Jones") 
and e.mgr=e2.empno and e2.ename="jones"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| ename | MgrName | 
|---|---|
| SCOTT | JONES | 
| FORD | JONES | 
%%sql
select * from emp
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select e.ename,d.deptno,d.dname,e.sal,g.grade from emp e,dept d,salgrade g 
where e.sal between g.losal and g.hisal and e.deptno=d.deptno order by e.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| ename | deptno | dname | sal | grade | 
|---|---|---|---|---|
| CLARK | 10 | ACCOUNTING | 2450.00 | 4 | 
| KING | 10 | ACCOUNTING | 5000.00 | 5 | 
| MILLER | 10 | ACCOUNTING | 1300.00 | 2 | 
| SMITH | 20 | RESEARCH | 800.00 | 1 | 
| JONES | 20 | RESEARCH | 2975.00 | 4 | 
| SCOTT | 20 | RESEARCH | 3000.00 | 4 | 
| ADAMS | 20 | RESEARCH | 1100.00 | 1 | 
| FORD | 20 | RESEARCH | 3000.00 | 4 | 
| ALLEN | 30 | SALES | 1600.00 | 3 | 
| WARD | 30 | SALES | 1250.00 | 2 | 
| MARTIN | 30 | SALES | 1250.00 | 2 | 
| BLAKE | 30 | SALES | 2850.00 | 4 | 
| TURNER | 30 | SALES | 1500.00 | 3 | 
| JAMES | 30 | SALES | 950.00 | 1 | 
%%sql
select e.ename,e.job,e.sal,g.grade,d.dname from emp e,dept d,salgrade g where e.deptno=d.deptno and  e.sal between g.losal and g.hisal
and e.job not in ("clerk") order by e.sal desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
10 rows affected.
| ename | job | sal | grade | dname | 
|---|---|---|---|---|
| KING | PRESIDENT | 5000.00 | 5 | ACCOUNTING | 
| SCOTT | ANALYST | 3000.00 | 4 | RESEARCH | 
| FORD | ANALYST | 3000.00 | 4 | RESEARCH | 
| JONES | MANAGER | 2975.00 | 4 | RESEARCH | 
| BLAKE | MANAGER | 2850.00 | 4 | SALES | 
| CLARK | MANAGER | 2450.00 | 4 | ACCOUNTING | 
| ALLEN | SALESMAN | 1600.00 | 3 | SALES | 
| TURNER | SALESMAN | 1500.00 | 3 | SALES | 
| WARD | SALESMAN | 1250.00 | 2 | SALES | 
| MARTIN | SALESMAN | 1250.00 | 2 | SALES | 
%%sql
select * from emp e where e.mgr is null
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
%%sql
select e1.ename,e1.deptno,max(e1.sal)as MaxSal from emp e1 group by e1.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| ename | deptno | MaxSal | 
|---|---|---|
| CLARK | 10 | 5000.00 | 
| SMITH | 20 | 3000.00 | 
| ALLEN | 30 | 2850.00 | 
%%sql
select * from emp e where e.sal=(select (max(e.sal)+min(e.sal))/2 from emp e)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
0 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|
%%sql
select e.deptno,count(*) from emp e group by e.deptno having 3<(count(*))
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| deptno | count(*) | 
|---|---|
| 20 | 5 | 
| 30 | 6 | 
%%sql
select d.dname,count(*) from dept d,emp e where d.deptno=e.deptno group by e.deptno having 3<=(select count(*) from emp e)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| dname | count(*) | 
|---|---|
| ACCOUNTING | 3 | 
| RESEARCH | 5 | 
| SALES | 6 | 
%%sql
select * from emp e where e.job="manager" and e.sal > (select avg( e1.sal) from emp e1 where e1.mgr=e.empno)group by e.deptno
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
%%sql
select e.ename,e.sal,e.comm from emp e where (e.sal+e.comm)>=any(select e1.sal from emp e1)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
4 rows affected.
| ename | sal | comm | 
|---|---|---|
| ALLEN | 1600.00 | 300.00 | 
| WARD | 1250.00 | 500.00 | 
| MARTIN | 1250.00 | 1400.00 | 
| TURNER | 1500.00 | 0.00 | 
import sqlalchemy
sqlalchemy.create_engine("mysql+mysqldb://root:****@localhost:3306/oracle_emp")
Engine(mysql+mysqldb://root:***@localhost:3306/oracle_emp)
%load_ext sql
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.QVLO2T66WEPI7JZ63PS3HMOHFEY472BC.gfortran-win_amd64.dll
  stacklevel=1)
%sql "mysql+mysqldb://root:*****@localhost:3306/oracle_emp"
%%sql
use oracle_emp;
create table dept(
  deptno int2,
  dname  varchar(14),
  loc    varchar(13),
  constraint pk_dept primary key (deptno)
);
 
create table emp(
  empno    int4,
  ename    varchar(10),
  job      varchar(9),
  mgr      int4,
  hiredate date,
  sal      decimal(7,2),
  comm     decimal(7,2),
  deptno   int2,
  constraint pk_emp primary key (empno),
  constraint fk_deptno foreign key (deptno) references dept (deptno)
);
 
create table bonus(
  ename varchar(10),
  job   varchar(9),
  sal   int4,
  comm  int4
);
 
create table salgrade(
  grade integer,
  losal integer,
  hisal integer
);
INSERT INTO EMP VALUES
        (7369, 'SMITH',  'CLERK',     7902,
        TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, 20);
INSERT INTO EMP VALUES
        (7499, 'ALLEN',  'SALESMAN',  7698,
        TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600,  300, 30);
INSERT INTO EMP VALUES
        (7521, 'WARD',   'SALESMAN',  7698,
        TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250,  500, 30);
INSERT INTO EMP VALUES
        (7566, 'JONES',  'MANAGER',   7839,
        TO_DATE('2-APR-1981', 'DD-MON-YYYY'),  2975, NULL, 20);
INSERT INTO EMP VALUES
        (7654, 'MARTIN', 'SALESMAN',  7698,
        TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
INSERT INTO EMP VALUES
        (7698, 'BLAKE',  'MANAGER',   7839,
        TO_DATE('1-MAY-1981', 'DD-MON-YYYY'),  2850, NULL, 30);
INSERT INTO EMP VALUES
        (7782, 'CLARK',  'MANAGER',   7839,
        TO_DATE('9-JUN-1981', 'DD-MON-YYYY'),  2450, NULL, 10);
INSERT INTO EMP VALUES
        (7788, 'SCOTT',  'ANALYST',   7566,
        TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
        (7839, 'KING',   'PRESIDENT', NULL,
        TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
INSERT INTO EMP VALUES
        (7844, 'TURNER', 'SALESMAN',  7698,
        TO_DATE('8-SEP-1981', 'DD-MON-YYYY'),  1500,    0, 30);
INSERT INTO EMP VALUES
        (7876, 'ADAMS',  'CLERK',     7788,
        TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
INSERT INTO EMP VALUES
        (7900, 'JAMES',  'CLERK',     7698,
        TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),   950, NULL, 30);
INSERT INTO EMP VALUES
        (7902, 'FORD',   'ANALYST',   7566,
        TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),  3000, NULL, 20);
INSERT INTO EMP VALUES
        (7934, 'MILLER', 'CLERK',     7782,
        TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO DEPT VALUES (20, 'RESEARCH',   'DALLAS');
INSERT INTO DEPT VALUES (30, 'SALES',      'CHICAGO');
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');
INSERT INTO SALGRADE VALUES (1,  700, 1200);
INSERT INTO SALGRADE VALUES (2, 1201, 1400);
INSERT INTO SALGRADE VALUES (3, 1401, 2000);
INSERT INTO SALGRADE VALUES (4, 2001, 3000);
INSERT INTO SALGRADE VALUES (5, 3001, 9999);
commit;
import sqlalchemy
sqlalchemy.create_engine("mysql+mysqldb://root:*****@localhost:3306/oracle_emp")
Engine(mysql+mysqldb://root:***@localhost:3306/oracle_emp)
%load_ext sql
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Users\tskir\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.QVLO2T66WEPI7JZ63PS3HMOHFEY472BC.gfortran-win_amd64.dll
  stacklevel=1)
%sql "mysql+mysqldb://root:****@localhost:3306/oracle_emp"
%%sql
select * from emp;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select distinct(job) from emp;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| job | 
|---|
| CLERK | 
| SALESMAN | 
| MANAGER | 
| ANALYST | 
| PRESIDENT | 
%%sql
select ename,sal from emp order by sal asc 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| ename | sal | 
|---|---|
| SMITH | 800.00 | 
| JAMES | 950.00 | 
| ADAMS | 1100.00 | 
| WARD | 1250.00 | 
| MARTIN | 1250.00 | 
| MILLER | 1300.00 | 
| TURNER | 1500.00 | 
| ALLEN | 1600.00 | 
| CLARK | 2450.00 | 
| BLAKE | 2850.00 | 
| JONES | 2975.00 | 
| SCOTT | 3000.00 | 
| FORD | 3000.00 | 
| KING | 5000.00 | 
%%sql
select ename,deptno,job from emp order by deptno asc,job desc;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| ename | deptno | job | 
|---|---|---|
| KING | 10 | PRESIDENT | 
| CLARK | 10 | MANAGER | 
| MILLER | 10 | CLERK | 
| JONES | 20 | MANAGER | 
| SMITH | 20 | CLERK | 
| ADAMS | 20 | CLERK | 
| SCOTT | 20 | ANALYST | 
| FORD | 20 | ANALYST | 
| ALLEN | 30 | SALESMAN | 
| WARD | 30 | SALESMAN | 
| MARTIN | 30 | SALESMAN | 
| TURNER | 30 | SALESMAN | 
| BLAKE | 30 | MANAGER | 
| JAMES | 30 | CLERK | 
%%sql
select job from emp group by job order by job desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| job | 
|---|
| SALESMAN | 
| PRESIDENT | 
| MANAGER | 
| CLERK | 
| ANALYST | 
%%sql
select * from emp where job="Manager"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
%%sql
select * from emp where hiredate<"1981-01-01"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
%%sql
select empno,ename,sal,sal/30 as dailysal,sal*12 as annualsal  from emp order by annualsal desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | sal | dailysal | annualsal | 
|---|---|---|---|---|
| 7839 | KING | 5000.00 | 166.666667 | 60000.00 | 
| 7788 | SCOTT | 3000.00 | 100.000000 | 36000.00 | 
| 7902 | FORD | 3000.00 | 100.000000 | 36000.00 | 
| 7566 | JONES | 2975.00 | 99.166667 | 35700.00 | 
| 7698 | BLAKE | 2850.00 | 95.000000 | 34200.00 | 
| 7782 | CLARK | 2450.00 | 81.666667 | 29400.00 | 
| 7499 | ALLEN | 1600.00 | 53.333333 | 19200.00 | 
| 7844 | TURNER | 1500.00 | 50.000000 | 18000.00 | 
| 7934 | MILLER | 1300.00 | 43.333333 | 15600.00 | 
| 7521 | WARD | 1250.00 | 41.666667 | 15000.00 | 
| 7654 | MARTIN | 1250.00 | 41.666667 | 15000.00 | 
| 7876 | ADAMS | 1100.00 | 36.666667 | 13200.00 | 
| 7900 | JAMES | 950.00 | 31.666667 | 11400.00 | 
| 7369 | SMITH | 800.00 | 26.666667 | 9600.00 | 
%%sql
select empno,ename,job,hiredate,floor(datediff(curdate(),hiredate)/365) as exp from emp where job="Manager"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | hiredate | exp | 
|---|---|---|---|---|
| 7566 | JONES | MANAGER | 1981-04-02 | 40 | 
| 7698 | BLAKE | MANAGER | 1981-05-01 | 40 | 
| 7782 | CLARK | MANAGER | 1981-06-09 | 40 | 
%%sql
select empno,ename,sal,floor(datediff(curdate(),hiredate)/365) as exp,mgr from emp where mgr=7698;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | sal | exp | mgr | 
|---|---|---|---|---|
| 7499 | ALLEN | 1600.00 | 40 | 7698 | 
| 7521 | WARD | 1250.00 | 40 | 7698 | 
| 7654 | MARTIN | 1250.00 | 39 | 7698 | 
| 7844 | TURNER | 1500.00 | 39 | 7698 | 
| 7900 | JAMES | 950.00 | 39 | 7698 | 
%%sql
select * from emp e where e.comm>e.sal
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
%%sql
select * from emp where hiredate between "1981-07-01"and "1981-12-31" order by job asc;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
%%sql 
select *,sal/30 as dailysal,floor(datediff(curdate(),hiredate)/365) as exp from emp where (sal/30)>100
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | dailysal | exp | 
|---|---|---|---|---|---|---|---|---|---|
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 166.666667 | 39 | 
%%sql
select * from emp where job like "clerk" or job like "analyst" order by job desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
6 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp where hiredate in ("1981-05-01", "1981-12-03" ,"1981-12-17" , "1980-01-19")
order by datediff(curdate(),hiredate) desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp where deptno in (10,20)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp where 1981=extract(year from hiredate)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
10 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp where 09=extract(month from hiredate) and 1981=extract(year from hiredate)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
%%sql
select *,sal*12 as annualsal from emp where sal*12  between 22000 and 45000 order by annualsal asc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | annualsal | 
|---|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 29400.00 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 34200.00 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 35700.00 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 36000.00 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 36000.00 | 
%%sql
select ename from emp where ename like "_____"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| ename | 
|---|
| SMITH | 
| ALLEN | 
| JONES | 
| BLAKE | 
| CLARK | 
| SCOTT | 
| ADAMS | 
| JAMES | 
%%sql
select ename from emp where length(ename)=5
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| ename | 
|---|
| SMITH | 
| ALLEN | 
| JONES | 
| BLAKE | 
| CLARK | 
| SCOTT | 
| ADAMS | 
| JAMES | 
%%sql
select ename from emp where ename like "s%" and length(ename)=5
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| ename | 
|---|
| SMITH | 
| SCOTT | 
%%sql
select ename from emp where ename like "s____"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| ename | 
|---|
| SMITH | 
| SCOTT | 
%%sql
select ename from emp where ename like "__r_";
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| ename | 
|---|
| WARD | 
| FORD | 
%%sql
select ename from emp where ename like "s___h";
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| ename | 
|---|
| SMITH | 
%%sql
select ename,hiredate from emp where 01=extract(month from hiredate);
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| ename | hiredate | 
|---|---|
| MILLER | 1982-01-23 | 
%%sql
select *, monthname(hiredate) from emp where monthname(hiredate) like "_a%";
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | monthname(hiredate) | 
|---|---|---|---|---|---|---|---|---|
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | May | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | January | 
%%sql
select * from emp where length(floor(sal))=4 and mod(floor(sal),10)=0;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
11 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select * from emp where ename like "%ll%";
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select * from emp where 
%%sql
select * from emp where deptno<>20
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
9 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
%%sql
select * from emp where job not like "president" and job not like "Manager"  order by sal asc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
10 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp where extract(year from hiredate)>1981 or extract(year from hiredate)<1981 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
4 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select * from emp where empno not like "78%"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
11 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select e.ename from emp e where e.mgr in (select empno from emp where job="Manager")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| ename | 
|---|
| ALLEN | 
| WARD | 
| MARTIN | 
| SCOTT | 
| TURNER | 
| JAMES | 
| FORD | 
| MILLER | 
%%sql
select * from emp where monthname(hiredate) not like "December"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
11 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 
%%sql
select * from emp where job="clerk" and deptno=20
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 
%%sql
select * from emp where deptno=30 or deptno=10 and 1981=extract(year from hiredate)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | None | 30 | 
%%sql
select * from emp where ename like "smith"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 
%%sql
select e.ename,d.deptno,d.loc from emp e,dept d where e.deptno=d.deptno and e.ename="smith"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
1 rows affected.
| ename | deptno | loc | 
|---|---|---|
| SMITH | 20 | DALLAS | 
%%sql
select  * from emp e,dept d where e.deptno=d.deptno and d.dname in ("Accounting","research") order by e.deptno asc;
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | deptno_1 | dname | loc | 
|---|---|---|---|---|---|---|---|---|---|---|
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 10 | ACCOUNTING | NEW YORK | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 10 | ACCOUNTING | NEW YORK | 
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | None | 10 | 10 | ACCOUNTING | NEW YORK | 
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 20 | RESEARCH | DALLAS | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 20 | RESEARCH | DALLAS | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 20 | RESEARCH | DALLAS | 
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | None | 20 | 20 | RESEARCH | DALLAS | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 20 | RESEARCH | DALLAS | 
%%sql
select e.hiredate,e.empno,e.ename,e.sal,e.job,floor(datediff(curdate(),e.hiredate)/365) as yearsExp,d.dname,d.loc from emp e,dept d where e.job in("Manager","Analyst") and e.deptno=d.deptno and d.loc in("New York","Dallas")
and e.comm is null and 37<floor(datediff(curdate(),e.hiredate)/365)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| hiredate | empno | ename | sal | job | yearsExp | dname | loc | 
|---|---|---|---|---|---|---|---|
| 1981-04-02 | 7566 | JONES | 2975.00 | MANAGER | 40 | RESEARCH | DALLAS | 
| 1981-06-09 | 7782 | CLARK | 2450.00 | MANAGER | 40 | ACCOUNTING | NEW YORK | 
| 1981-12-03 | 7902 | FORD | 3000.00 | ANALYST | 39 | RESEARCH | DALLAS | 
%%sql
select e.empno,e.ename,e.sal,d.dname,d.loc,e.deptno,e.job from emp e,dept d where e.deptno=d.deptno
and d.loc="chicago" or d.dname="accounting" and sal*12 >28000 and sal not in(3000,2800) and e.job not like "manager" 
and (e.empno like '__7%' or '__8%' ) order by e.deptno asc,e.job desc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
6 rows affected.
| empno | ename | sal | dname | loc | deptno | job | 
|---|---|---|---|---|---|---|
| 7499 | ALLEN | 1600.00 | SALES | CHICAGO | 30 | SALESMAN | 
| 7521 | WARD | 1250.00 | SALES | CHICAGO | 30 | SALESMAN | 
| 7654 | MARTIN | 1250.00 | SALES | CHICAGO | 30 | SALESMAN | 
| 7844 | TURNER | 1500.00 | SALES | CHICAGO | 30 | SALESMAN | 
| 7698 | BLAKE | 2850.00 | SALES | CHICAGO | 30 | MANAGER | 
| 7900 | JAMES | 950.00 | SALES | CHICAGO | 30 | CLERK | 
%%sql
select * from emp e, salgrade s,bonus b where 
%%sql
select e.ename,e.sal,g.grade from emp e,salgrade g where e.sal between g.losal and g.hisal and g.grade in (2,3)
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| ename | sal | grade | 
|---|---|---|
| ALLEN | 1600.00 | 3 | 
| WARD | 1250.00 | 2 | 
| MARTIN | 1250.00 | 2 | 
| TURNER | 1500.00 | 3 | 
| MILLER | 1300.00 | 2 | 
%%sql
select e.ename,e.job,g.grade from emp e, salgrade g where e.sal between g.losal and g.hisal and e.job in ("Analyst","Manager")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
5 rows affected.
| ename | job | grade | 
|---|---|---|
| FORD | ANALYST | 4 | 
| SCOTT | ANALYST | 4 | 
| CLARK | MANAGER | 4 | 
| BLAKE | MANAGER | 4 | 
| JONES | MANAGER | 4 | 
%%sql
select e.empno,e.ename,e.sal,d.deptno,d.dname,g.grade,floor((datediff(curdate(),e.hiredate))/365) as exp,sal*12 as annulaSal 
from emp e,dept d,salgrade g where e.deptno in(10,20) and e.deptno=d.deptno and e.sal between g.losal and g.hisal 
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | sal | deptno | dname | grade | exp | annulaSal | 
|---|---|---|---|---|---|---|---|
| 7876 | ADAMS | 1100.00 | 20 | RESEARCH | 1 | 34 | 13200.00 | 
| 7369 | SMITH | 800.00 | 20 | RESEARCH | 1 | 40 | 9600.00 | 
| 7934 | MILLER | 1300.00 | 10 | ACCOUNTING | 2 | 39 | 15600.00 | 
| 7902 | FORD | 3000.00 | 20 | RESEARCH | 4 | 39 | 36000.00 | 
| 7788 | SCOTT | 3000.00 | 20 | RESEARCH | 4 | 34 | 36000.00 | 
| 7566 | JONES | 2975.00 | 20 | RESEARCH | 4 | 40 | 35700.00 | 
| 7782 | CLARK | 2450.00 | 10 | ACCOUNTING | 4 | 40 | 29400.00 | 
| 7839 | KING | 5000.00 | 10 | ACCOUNTING | 5 | 39 | 60000.00 | 
%%sql
select e.empno,d.loc,g.grade,d.dname,e.hiredate,e.sal from emp e,dept d,salgrade g where e.sal between g.losal and g.hisal and g.grade between 2 and 4 and e.deptno=d.deptno
and d.dname not like "op%" and d.dname not like "%s" and e.job like "%a%" and 1981=extract(year from e.hiredate) and monthname(e.hiredate)<>"March" and monthname(e.hiredate)<>"September"
and e.sal%100<>00 order by g.grade asc
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
2 rows affected.
| empno | loc | grade | dname | hiredate | sal | 
|---|---|---|---|---|---|
| 7566 | DALLAS | 4 | RESEARCH | 1981-04-02 | 2975.00 | 
| 7782 | NEW YORK | 4 | ACCOUNTING | 1981-06-09 | 2450.00 | 
%%sql
SELECT e.empno,e.ename, (SELECT dname FROM dept d WHERE d.deptno=e.deptno)dname
FROM emp e
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
14 rows affected.
| empno | ename | dname | 
|---|---|---|
| 7369 | SMITH | RESEARCH | 
| 7499 | ALLEN | SALES | 
| 7521 | WARD | SALES | 
| 7566 | JONES | RESEARCH | 
| 7654 | MARTIN | SALES | 
| 7698 | BLAKE | SALES | 
| 7782 | CLARK | ACCOUNTING | 
| 7788 | SCOTT | RESEARCH | 
| 7839 | KING | ACCOUNTING | 
| 7844 | TURNER | SALES | 
| 7876 | ADAMS | RESEARCH | 
| 7900 | JAMES | SALES | 
| 7902 | FORD | RESEARCH | 
| 7934 | MILLER | ACCOUNTING | 
%%sql
select * from emp e where e.sal>(select b.sal from emp b where b.ename="blake")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
4 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | None | 20 | 
| 7839 | KING | PRESIDENT | None | 1981-11-07 | 5000.00 | None | 10 | 
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | None | 20 | 
%%sql
select * from emp e where e.job=(select a.job from emp a where a.ename="Allen") and e.ename not like "Allen"
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
3 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | 
|---|---|---|---|---|---|---|---|
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 
%%sql
select *,(datediff(curdate(),hiredate)/365) as exp from emp e where (datediff(curdate(),hiredate)/365)>(select (datediff(curdate(),hiredate)/365) from emp k where k.ename like "King")
 * mysql+mysqldb://root:***@localhost:3306/oracle_emp
8 rows affected.
| empno | ename | job | mgr | hiredate | sal | comm | deptno | exp | 
|---|---|---|---|---|---|---|---|---|
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | None | 20 | 40.6192 | 
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 40.4411 | 
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 40.4356 | 
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | None | 20 | 40.3288 | 
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 39.8384 | 
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | None | 30 | 40.2493 | 
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | None | 10 | 40.1425 | 
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 39.8932 | 
Explore the Components of a Modern Data Warehouse and Data Ingestion.
Azure data analytical components for modern data warehousing.