sql2
sql2
sql2
-- another one
select * from emp where sal > 1251 and deptno = 30;
-- another one
select deptno, job, max(sal), min(sal), avg(sal) from emp group by deptno, job
Order by deptno asc;
select deptno, max(sal) from emp group by deptno having deptno > 15 order by deptno
asc;
select deptno, sum(sal) from emp group by deptno having sum(sal) > 3000;
select deptno, count(*) from emp group by deptno having count(*) > 4;
select job, count(*) from emp where sal> 2000 group by job;
select * from emp where extract(month from hiredate) = 8 and extract(year from
hiredate) = 1980 and sal between 1500 and 2500;
select ename, date_format(hiredate, '%d/%m/%y') from emp where job='clerk' and comm
is not null;
update emp
set sal = sal + (sal + ifnull(comm, 0))*0.15;
update emp
set job = 'manager', mgr = 7777
where deptno = 10;'
update emp
set job = 'senior clerk'
where ename = 'smith';
update emp
set sal = sal + 0.15*(sal)
where comm is not null and comm != 0;
set sql_safe_updates = 0;
update emp
set sal = (select sal from (select sal from emp where ename='Miller') as temp_sal)
where ename = 'Allen';
update emp
set sal = (select sal from (select sal from emp where ename='Miller') as temp_sal)
where deptno = (select deptno from (select deptno from emp where ename='Wall') as
temp_deptno);
select ename, (select dname from dept where dept.deptno = emp.deptno) from emp;
select empno, ename, sal, comm, (select grade from salgrade where emp.sal between
salgrade.losal and salgrade.hisal) as sal_grade from emp;
select empno, ename, mgr, (select ename from emp e2 where e2.empno = e1.mgr) as
mgrname from emp e1;
------------
-----------------------------------
-----------------------------------------------
insert into faculty values (10, 'kjzhcjhz', 'a', 'b'), (11, 'sdd', 'x', 'z'),
(12, 'lksjk', 'a', 'x'), (13, 'ksdjlkj', 'a', 'b');
insert into room values (100, 'jasmin', '1st floor'), (101, 'Rose', '2nd floor'),
(105, 'Lotus', '1st floor'), (103, 'Mogra', '1st floor');
insert into courses values (121, 'DBDA', 100, 10), (131, 'DAC', 101, null),
(141, 'DITISS', null, null), (151, 'DIOT', 105, 12);
-- 1
select c.cid, cname
from courses c
where c.rid is null;
-- 2
select f.fid, f.fname
from faculty f
left join courses c on f.fid = c.fid
where c.fid is null;
-- 3
select rid, rname, rloc,
case
when rid in (select rid from courses) then 'not available'
else 'available'
end as availability
from room;
-- 1,2 / 4
select r.rid, r.rname
from room r
left join courses c on r.rid = c.rid
where c.rid is null;
-- 5
select f.fname, c.cname
from faculty f
join courses c on c.fid = f.fid
where f.sp_skill1 = 'database' or f.sp_skill2 = 'database';
-- 6
select c.cid, c.cname, f.fname, r.rname, r.rloc
from courses c
left join faculty f on c.fid = f.fid
left join room r on c.rid = r.rid;
-----------------------------------------------
use iacsd0925;
insert into salesman values (11, 'Rahul', 'Pune'), (12, 'Kirti', 'Mumbai'), (13,
'Prasad', 'Nashik')
,(14, 'Arnav', 'Amaravati');
insert into category values (1, 'chips', 'very crunchy'), (2, 'choclate', 'very
chocolaty'),
(3, 'snacks', 'yummy'), (4, 'cold drinks', 'Thanda thanda cool cool');
insert into product values (123, 'lays', 30, 30.00, 1, 12), (111, 'pepsi', 40,
50.00, 4, 11),
(134, 'nachos', 50 ,50.00, 1 ,12), (124, 'dairy milk', 40, 60.00, 2, 14),
(125,'pringles', 40, 60.00, 1, 14);
select * from product where catid = (select cid from category where cname = 'chips'
limit 1);