├── DBMS MOCK ├── A.sql ├── B.sql ├── C.sql ├── D.sql ├── E.sql ├── F.sql ├── G.sql ├── H.sql └── Questions.sql ├── Day-3 ├── Assignments │ ├── Solution_015.txt │ ├── Solution_016.txt │ ├── Solution_017.txt │ ├── Solution_018.txt │ ├── Solution_019.txt │ ├── Solution_020.txt │ ├── Solution_021.txt │ ├── Solution_022.txt │ ├── Solution_023.txt │ ├── Solution_024.txt │ ├── Solution_025.txt │ ├── Solution_026.txt │ ├── Solution_027.txt │ ├── Solution_028.txt │ ├── Solution_029.txt │ ├── Solution_030.txt │ ├── Solution_031.txt │ ├── Solution_032.txt │ ├── Solution_033.txt │ ├── Solution_034.txt │ ├── Solution_035.txt │ ├── Solution_036.txt │ ├── Solution_037.txt │ ├── Solution_038.txt │ └── Solution_039.txt └── Excercises │ ├── Excer_21.txt │ └── Excer_22.txt ├── Day-4 ├── Assignments │ ├── Solution_040.txt │ ├── Solution_041.txt │ ├── Solution_042.txt │ ├── Solution_043.txt │ ├── Solution_044.txt │ ├── Solution_045.txt │ ├── Solution_046.txt │ ├── Solution_047.txt │ ├── Solution_048.txt │ ├── Solution_049.txt │ ├── Solution_050.txt │ ├── Solution_051.txt │ ├── Solution_052.txt │ ├── Solution_053.txt │ ├── Solution_054.txt │ ├── Solution_055.txt │ ├── Solution_056.txt │ ├── Solution_057.txt │ ├── Solution_058.txt │ ├── Solution_059.txt │ ├── Solution_060.txt │ ├── Solution_061.txt │ ├── Solution_062.txt │ ├── Solution_063.txt │ ├── Solution_064.txt │ ├── Solution_065.txt │ └── Solution_066.txt └── Excercises │ ├── Excer_23.txt │ ├── Excer_24.txt │ ├── Excer_25.txt │ ├── Excer_26.txt │ ├── Excer_27.txt │ ├── Excer_28.txt │ ├── Excer_29.txt │ ├── Excer_30.txt │ ├── Excer_31.txt │ ├── Excer_32.txt │ ├── Excer_33.txt │ ├── Excer_34.txt │ ├── Excer_35.txt │ ├── Excer_36.txt │ ├── Excer_37.txt │ ├── Excer_38.txt │ └── Excer_39.txt ├── Day-5 ├── Assignments │ ├── Solution_067.txt │ ├── Solution_068.txt │ ├── Solution_069.txt │ ├── Solution_070.txt │ ├── Solution_071.txt │ ├── Solution_072.txt │ ├── Solution_073.txt │ ├── Solution_074.txt │ ├── Solution_075.txt │ ├── Solution_076.txt │ ├── Solution_077.txt │ ├── Solution_078.txt │ ├── Solution_079.txt │ ├── Solution_080.txt │ ├── Solution_081.txt │ ├── Solution_082.txt │ ├── Solution_083.txt │ ├── Solution_084.txt │ ├── Solution_085.txt │ ├── Solution_086.txt │ ├── Solution_087.txt │ ├── Solution_088.txt │ ├── Solution_089.txt │ ├── Solution_090.txt │ ├── Solution_091.txt │ └── Solution_092.txt └── Excercises │ ├── Excer_40.txt │ ├── Excer_41.txt │ ├── Excer_42.txt │ ├── Excer_43.txt │ ├── Excer_44.txt │ ├── Excer_45.txt │ ├── Excer_46.txt │ ├── Excer_47.txt │ ├── Excer_48.txt │ ├── Excer_49.txt │ ├── Excer_50.txt │ ├── Excer_51.txt │ ├── Excer_52.txt │ ├── Excer_53.txt │ ├── Excer_54.txt │ ├── Excer_55.txt │ ├── Excer_56.txt │ ├── Excer_57.txt │ └── Excer_58.txt ├── Day-6 ├── Assignments │ ├── Solution_093.txt │ ├── Solution_094.txt │ ├── Solution_095.txt │ ├── Solution_096.txt │ ├── Solution_097.txt │ ├── Solution_098.txt │ ├── Solution_099.txt │ ├── Solution_100.txt │ ├── Solution_101.txt │ ├── Solution_102.txt │ ├── Solution_103.txt │ ├── Solution_104.txt │ ├── Solution_105.txt │ ├── Solution_106.txt │ ├── Solution_107.txt │ ├── Solution_108.txt │ ├── Solution_109.txt │ └── Solution_110.txt └── Excercises │ ├── Excer_59.txt │ ├── Excer_60.txt │ ├── Excer_61.txt │ ├── Excer_62.txt │ ├── Excer_63.txt │ ├── Excer_64.txt │ ├── Excer_65.txt │ └── Excer_66.txt └── README.md /DBMS MOCK/A.sql: -------------------------------------------------------------------------------- 1 | select 2 | to_number(substr(giftid,2)) as giftnum, 3 | giftname, round((price*discount/100),0) AS pricereduction 4 | from gift 5 | WHERE category = 'Utilities' 6 | -------------------------------------------------------------------------------- /DBMS MOCK/B.sql: -------------------------------------------------------------------------------- 1 | select distinct 2 | gfo.customerid, 3 | gfo.giftid 4 | from gift g ,giftorder gfo 5 | WHERE g.giftid = gfo.giftid 6 | AND g.category != 'Home Decor' 7 | -------------------------------------------------------------------------------- /DBMS MOCK/C.sql: -------------------------------------------------------------------------------- 1 | select gfo.giftid, 2 | NVL(to_char(gfo1.orderid), 'NA') AS orders 3 | from gift gfo LEFT join giftorder gfo1 4 | on gfo.giftid = gfo1.giftid AND gfo1.shippingcity = 'Mysore' 5 | -------------------------------------------------------------------------------- /DBMS MOCK/D.sql: -------------------------------------------------------------------------------- 1 | SELECT g.giftid, g.giftname, g.availability, count (gf.giftid) AS nooforders 2 | FROM gift g, giftorder gf 3 | WHERE g.giftid = gf.giftid AND g.availability > 40 4 | GROUP BY g.giftid, g.giftname, g.availability 5 | HAVING count (gf.giftid) > 1 6 | -------------------------------------------------------------------------------- /DBMS MOCK/E.sql: -------------------------------------------------------------------------------- 1 | select nvl(to_char(orderid),'NA') as ordernum, nvl(c.customerid,'N') as customer 2 | from customer1 c full join giftorder g 3 | on c.customerid = g.customerid and location = 'Bangalore' 4 | -------------------------------------------------------------------------------- /DBMS MOCK/F.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT gf.orderid, gf.customerid, gf.giftid 2 | FROM giftorder gf, gift g, giftorder gf1 3 | WHERE g.GIFTID = gf.GIFTID AND gf.CUSTOMERID = gf1.CUSTOMERID AND g.CATEGORY = 'Home Decor' 4 | GROUP BY gf.orderid, gf.customerid, gf.giftid 5 | HAVING count(gf.customerid) > 1 6 | 7 | -------------------------------------------------------------------------------- /DBMS MOCK/G.sql: -------------------------------------------------------------------------------- 1 | SELECT g1.customerid,customername,round(sum(price*quantity*(1-discount/100))) totalbill 2 | FROM giftorder g1,gift g,customer1 c WHERE g1.giftid=g.giftid AND g1.CUSTOMERID=c.customerid GROUP BY g1.customerid,customername HAVING 3 | round(sum(price*quantity*(1-discount/100)))= 4 | (SELECT round(max(sum(price*quantity*(1-discount/100)))) FROM giftorder g1,gift g WHERE g1.giftid=g.giftid GROUP BY customerid) 5 | -------------------------------------------------------------------------------- /DBMS MOCK/H.sql: -------------------------------------------------------------------------------- 1 | SELECT gf.orderid, gf.giftid, gf.customerid 2 | FROM giftorder gf 3 | WHERE gf.customerid = 4 | (SELECT c1.customerid FROM customer1 c1 WHERE location = 'Delhi' AND c1.customerid =gf.customerid ) 5 | AND gf.giftid= 6 | (SELECT g1.giftid FROM gift g1 WHERE category != 'Showpiece' AND g1.giftid = gf.giftid) 7 | AND gf.orderid = 8 | (SELECT gf1.orderid FROM giftorder gf1 WHERE shippingcity = 'Chennai' AND gf1.orderid = gf.orderid) 9 | -------------------------------------------------------------------------------- /DBMS MOCK/Questions.sql: -------------------------------------------------------------------------------- 1 | drop table gift; 2 | drop table customer1; 3 | drop table giftorder; 4 | 5 | create table gift( 6 | giftid varchar2(5) PRIMARY KEY CHECK(giftid LIKE 'G%'), 7 | giftname varchar2(20) UNIQUE NOT NULL, 8 | category varchar2(15), 9 | price NUMBER check(price>0), 10 | discount NUMBER, 11 | availability NUMBER 12 | ); 13 | 14 | create table customer1( 15 | customerid varchar2(5) PRIMARY KEY CHECK(customerid LIKE 'C%'), 16 | customername VARCHAR2(15), 17 | location VARCHAR2(15) 18 | ); 19 | 20 | create table giftorder( 21 | orderid NUMBER PRIMARY KEY, 22 | customerid VARCHAR2(5) REFERENCES customer1(customerid), 23 | giftid VARCHAR2(5) REFERENCES gift(giftid), 24 | quantity NUMBER, 25 | shippingcity VARCHAR2(15) 26 | ); 27 | 28 | delete from giftorder; 29 | delete from gift; 30 | delete from customer1; 31 | 32 | INSERT INTO gift VALUES('G101','Dream Catcher','Showpiece','500','10','63'); 33 | INSERT INTO gift VALUES('G102','Cinnamon Candles','Home Decor','550','5','35'); 34 | INSERT INTO gift VALUES('G103','Watch Box','Utilities','2000','20','18'); 35 | INSERT INTO gift VALUES('G104','Music Plant Lamp','Home Decor','1500','15','5'); 36 | INSERT INTO gift VALUES('G105','Crystal Platter','Utilities','2999','7','10'); 37 | INSERT INTO gift VALUES('G106','Crystal Chariot','Showpiece','2000','15','32'); 38 | INSERT INTO gift VALUES('G107','Wood Coaster Set','Utilities','1300','30','30'); 39 | INSERT INTO gift VALUES('G108','Golden Foil Rose','Showpiece','500','30','30'); 40 | INSERT INTO gift VALUES('G109','Photo Frames','Home Decor','500','30','30'); 41 | INSERT INTO customer1 VALUES('C101','Jack','Delhi'); 42 | INSERT INTO customer1 VALUES('C102','John','Bangalore'); 43 | INSERT INTO customer1 VALUES('C103','Sam','Mumbai'); 44 | INSERT INTO customer1 VALUES('C104','Andrew','Bangalore'); 45 | INSERT INTO customer1 VALUES('C105','Anne','Delhi'); 46 | INSERT INTO customer1 VALUES('C106','Maria','Mumbai'); 47 | INSERT INTO customer1 VALUES('C107','Jeny','Bangalore'); 48 | INSERT INTO giftorder VALUES('1001','C102','G104','2','Delhi'); 49 | INSERT INTO giftorder VALUES('1002','C103','G102','5','Bangalore'); 50 | INSERT INTO giftorder VALUES('1003','C105','G101','3','Bangalore'); 51 | INSERT INTO giftorder VALUES('1004','C102','G104','1','Bangalore'); 52 | INSERT INTO giftorder VALUES('1005','C101','G103','9','Mysore'); 53 | INSERT INTO giftorder VALUES('1006','C102','G101','8','Mumbai'); 54 | INSERT INTO giftorder VALUES('1007','C105','G106','4','Chennai'); 55 | INSERT INTO giftorder VALUES('1008','C105','G107','4','Chennai'); 56 | INSERT INTO giftorder VALUES('1009','C105','G108','5','Mumbai'); 57 | INSERT INTO giftorder VALUES('1010','C106','G105','6','Mysore'); 58 | -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_015.txt: -------------------------------------------------------------------------------- 1 | insert into shopper values (101,'Mark Jane','Male',1234567890,'Allen Street, New York') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_016.txt: -------------------------------------------------------------------------------- 1 | insert into article values('A1001','Mouse',500,0,'C') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_017.txt: -------------------------------------------------------------------------------- 1 | insert into store values ('Loyal World','Infy Campus, Mysore','Rohan Kumar') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_018.txt: -------------------------------------------------------------------------------- 1 | insert into bill values (1001,'Loyal World',101,'A1001',1000,'20-OCT-15',2) -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_019.txt: -------------------------------------------------------------------------------- 1 | insert into supplier values ('S501', 'Avaya Ltd', 9012345678,'Mysore') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_020.txt: -------------------------------------------------------------------------------- 1 | select descr, price from item where descr like '%Hard%' -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_021.txt: -------------------------------------------------------------------------------- 1 | select quotationid, sname, itemcode, quotedprice, qdate, qstatus from quotation where qstatus <> 'Accepted' -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_022.txt: -------------------------------------------------------------------------------- 1 | select designation,salary from empdetails where designation in ('Manager', 'Billing Staff') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_023.txt: -------------------------------------------------------------------------------- 1 | select roid, location from retailoutlet where managerid is NULL -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_024.txt: -------------------------------------------------------------------------------- 1 | select orderid, quotationid, status from orders where orderdate between '1-Dec-2014' and '1-Jan-2015' -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_025.txt: -------------------------------------------------------------------------------- 1 | select itemcode, descr, price from item where category = 'B' and descr like '%Shirt' or descr like '%Skirt' -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_026.txt: -------------------------------------------------------------------------------- 1 | select distinct designation, salary from empdetails -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_027.txt: -------------------------------------------------------------------------------- 1 | select itemcode,descr, price from item -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_028.txt: -------------------------------------------------------------------------------- 1 | select quotationid,sname from quotation where qstatus in ('Accepted','Rejected') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_029.txt: -------------------------------------------------------------------------------- 1 | select itemcode , descr, price from item where descr like '_r%' -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_030.txt: -------------------------------------------------------------------------------- 1 | select distinct itemtype from item -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_031.txt: -------------------------------------------------------------------------------- 1 | select orderid, quotationid, status, pymtdate 2 | from orders where pymtdate is null -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_032.txt: -------------------------------------------------------------------------------- 1 | select distinct itemtype, category from item -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_033.txt: -------------------------------------------------------------------------------- 1 | select empid,salary as "Current Salary", salary *1.1 as "New Salary", salary * 0.1 as "Incremented Amount" 2 | from empdetails -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_034.txt: -------------------------------------------------------------------------------- 1 | insert into city values ('Mysore') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_035.txt: -------------------------------------------------------------------------------- 1 | insert into address 2 | values (350,'Electronics City','Mysore',570018,'Karnataka') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_036.txt: -------------------------------------------------------------------------------- 1 | insert into article 2 | values ('A1002','Keyboard',1000,10,'B') -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_037.txt: -------------------------------------------------------------------------------- 1 | select quotationid, qdate ,quotedprice from quotation where quotedprice > 1400 and quotedprice < 2150 -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_038.txt: -------------------------------------------------------------------------------- 1 | select itemtype, descr ,price from item 2 | where price > 4000 -------------------------------------------------------------------------------- /Day-3/Assignments/Solution_039.txt: -------------------------------------------------------------------------------- 1 | select designation, salary from empdetails 2 | where designation in ('Manager','Billing Staff') 3 | and salary between 2500 and 5000 -------------------------------------------------------------------------------- /Day-3/Excercises/Excer_21.txt: -------------------------------------------------------------------------------- 1 | delete from saledetail where saleid = 1004 -------------------------------------------------------------------------------- /Day-3/Excercises/Excer_22.txt: -------------------------------------------------------------------------------- 1 | delete from saledetail where quantity > 5 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_040.txt: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT itemtype, 2 | CASE 3 | WHEN price BETWEEN 0 AND 499 THEN 'Cheap' 4 | WHEN price BETWEEN 500 AND 1999 THEN 'Affordable' 5 | WHEN price BETWEEN 2000 AND 4999 THEN 'Expensive' 6 | ELSE 'Very Expensive' 7 | END AS Classification 8 | FROM item 9 | ORDER BY itemtype -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_041.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | To_CHAR(qdate,'Month') AS MONTH, 3 | COUNT(To_CHAR(qdate,'Month')) AS QUOTATIONCOUNT 4 | FROM quotation 5 | GROUP BY To_CHAR(qdate,'Month') -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_042.txt: -------------------------------------------------------------------------------- 1 | SELECT orderid, 2 | ROUND(months_between(pymtdate, orderdate),2) AS "No of Months" 3 | FROM orders 4 | WHERE months_between(pymtdate, orderdate) > 0.1 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_043.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | empid, 3 | salary as "Current Salary", 4 | salary*1.20 as "New Salary", 5 | salary*0.20 as "Incremented Amount" 6 | FROM empdetails 7 | where designation = 'Manager' -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_044.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | itemcode 3 | FROM 4 | item 5 | WHERE (qtyonhand - reorderlevel) > 50 OR (qtyonhand - reorderlevel) < -50 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_045.txt: -------------------------------------------------------------------------------- 1 | SELECT itemcode,avg(qtyavailable) as "Average Quantity" 2 | FROM retailstock 3 | GROUP BY itemcode 4 | HAVING avg(qtyavailable) < 75 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_046.txt: -------------------------------------------------------------------------------- 1 | select pymtmode, count(pymtmode) as pymtcount from orders 2 | where to_number(to_char(pymtdate,'YYYY')) < 2015 3 | group by pymtmode 4 | having count(pymtmode) > 1 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_047.txt: -------------------------------------------------------------------------------- 1 | SELECT sname,avg(quotedprice) AS "Average quoted price" 2 | FROM quotation 3 | WHERE qstatus = 'Closed' 4 | GROUP BY sname 5 | HAVING avg(quotedprice) >500 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_048.txt: -------------------------------------------------------------------------------- 1 | SELECT itemtype, category, round(avg(price),2) AS "Average item price" 2 | FROM item 3 | WHERE itemtype = 'Computer' OR itemtype = 'FMCG' 4 | GROUP BY itemtype, category 5 | HAVING avg(price) < 2000 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_049.txt: -------------------------------------------------------------------------------- 1 | SELECT job, avg(sal) AS "Average Salary" 2 | FROM emp 3 | WHERE job = 'MANAGER' OR job = 'ANALYST' 4 | GROUP BY job 5 | HAVING avg(sal) > 1500 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_050.txt: -------------------------------------------------------------------------------- 1 | SELECT job, deptno, avg(sal) AS avgsalary 2 | FROM emp 3 | WHERE deptno IN (10,20) AND sal >2000 4 | GROUP BY job,deptno 5 | HAVING avg(sal) > 2500 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_051.txt: -------------------------------------------------------------------------------- 1 | SELECT empid,empname,salary, 2 | CASE 3 | WHEN designation = 'Administrator' THEN salary * 1.10 4 | WHEN designation = 'Manager' THEN salary * 1.05 5 | WHEN designation = 'Billing Staff' THEN salary * 1.20 6 | WHEN designation = 'Security' THEN salary * 1.25 7 | ELSE salary * 1.02 8 | END increasedsalary 9 | FROM empdetails -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_052.txt: -------------------------------------------------------------------------------- 1 | SELECT EmpId, Salary, 2 | CASE 3 | WHEN salary < 2500 THEN 'Class 3' 4 | WHEN salary BETWEEN 2500 AND 5000 THEN 'Class 2' 5 | ELSE 'Class 1' 6 | END salgrade 7 | FROM empdetails -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_053.txt: -------------------------------------------------------------------------------- 1 | SELECT itemcode, price AS "Old Price", ROUND(price * 0.745,2) AS "New Price" 2 | FROM item 3 | WHERE itemtype = 'FMCG' -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_054.txt: -------------------------------------------------------------------------------- 1 | SELECT empid, empname, worksin 2 | FROM empdetails 3 | WHERE designation = 'Billing Staff' -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_055.txt: -------------------------------------------------------------------------------- 1 | SELECT orderid, status, NVL(pymtmode,'Payment yet not done') as pymtmode 2 | FROM orders 3 | -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_056.txt: -------------------------------------------------------------------------------- 1 | select descr 2 | from item 3 | where length(descr) > 15 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_057.txt: -------------------------------------------------------------------------------- 1 | select substr(roid,2) as NUMERICROID 2 | from retailoutlet -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_058.txt: -------------------------------------------------------------------------------- 1 | select to_char(sysdate,'Mon/DD/YYYY Day') as currentdate 2 | from dual -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_059.txt: -------------------------------------------------------------------------------- 1 | SELECT count(status) AS TOTALORDERSCOUNT, count(pymtmode) AS PAIDORDERSCOUNT 2 | FROM orders -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_060.txt: -------------------------------------------------------------------------------- 1 | SELECT orderid, pymtdate-orderdate AS NOOFDAYS 2 | FROM orders 3 | -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_061.txt: -------------------------------------------------------------------------------- 1 | SELECT count (DISTINCT itemtype) AS NOOFITEMTYPES 2 | FROM item 3 | -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_062.txt: -------------------------------------------------------------------------------- 1 | SELECT max (salary) AS maxsal, min(salary) AS minsal, sum(salary) AS totalsal, avg(salary) AS avgsal 2 | FROM empdetails 3 | -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_063.txt: -------------------------------------------------------------------------------- 1 | SELECT sname, avg(quotedprice) as "Average quoted price" 2 | FROM quotation 3 | WHERE quotedprice > 1000 AND qstatus = 'Closed' 4 | GROUP BY sname 5 | HAVING avg(quotedprice) < 4500 -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_064.txt: -------------------------------------------------------------------------------- 1 | SELECT count(itemcode) AS NOOFITEMS FROM item -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_065.txt: -------------------------------------------------------------------------------- 1 | SELECT orderid, months_between(orderdate,pymtdate) AS "No of Months" 2 | FROM orders 3 | -------------------------------------------------------------------------------- /Day-4/Assignments/Solution_066.txt: -------------------------------------------------------------------------------- 1 | SELECT SUM(quotedprice) AS totalprice 2 | FROM quotation 3 | where qstatus = 'Accepted' AND TO_CHAR(qdate,'Mon') = 'Jun' -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_23.txt: -------------------------------------------------------------------------------- 1 | select prodid,pdesc,category from product 2 | where upper(category) = 'ELECTRONICS' -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_24.txt: -------------------------------------------------------------------------------- 1 | select prodid, substr(pdesc,1,5) as pdesc_five, category 2 | from product -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_25.txt: -------------------------------------------------------------------------------- 1 | select count(sid) as sale_count from sale 2 | where sldate between add_months(sysdate,-40) and sysdate -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_26.txt: -------------------------------------------------------------------------------- 1 | SELECT NVL(pdesc,'No Description') as pdesc,discount FROM product 2 | -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_27.txt: -------------------------------------------------------------------------------- 1 | select prodid, category, price, discount from product 2 | order by category desc, price -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_28.txt: -------------------------------------------------------------------------------- 1 | select prodid, category, discount from product where category in ('Sports','Apparel') 2 | order by category, discount -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_29.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | To_CHAR(sldate,'Month') AS MONTH, 3 | count(To_CHAR(sldate,'Month')) as Number_sale 4 | FROM SALE 5 | GROUP BY To_CHAR(sldate,'Month') 6 | ORDER BY COUNT(To_CHAR(sldate,'Month')) desc -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_30.txt: -------------------------------------------------------------------------------- 1 | select prodid,sum(quantity) as QTY_sold 2 | from Saledetail 3 | where quantity > 1 4 | group by prodid 5 | having count(prodid)>1 -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_31.txt: -------------------------------------------------------------------------------- 1 | Select prodid, pdesc, price as "Old_Price", round(price*0.775,2) as "New_Price" from product where category = 'Sports' -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_32.txt: -------------------------------------------------------------------------------- 1 | select saleid, round(months_between(sysdate,sldate),1) as month_aged from sale -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_33.txt: -------------------------------------------------------------------------------- 1 | select round(avg(price),2) as "Avg", min(price) as "Min",max(price) as "Max", count(price) as "Total" from product -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_34.txt: -------------------------------------------------------------------------------- 1 | select sname||' is from '||location as result from salesman -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_35.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | TO_CHAR(TO_DATE('Jan/10/2015','Mon/DD/YYYY'),'Month') AS MONTH, 3 | TO_NUMBER(REPLACE('2,50,000.00',',','')) AS AMOUNT 4 | FROM dual -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_36.txt: -------------------------------------------------------------------------------- 1 | select prodid,pdesc,price 2 | from product 3 | order by price desc,prodid desc -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_37.txt: -------------------------------------------------------------------------------- 1 | select prodid,pdesc,price 2 | from product 3 | order by pdesc -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_38.txt: -------------------------------------------------------------------------------- 1 | select location,count(location) as number_sman from salesman 2 | group by location -------------------------------------------------------------------------------- /Day-4/Excercises/Excer_39.txt: -------------------------------------------------------------------------------- 1 | select location,count(location) as number_sman from salesman 2 | group by location -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_067.txt: -------------------------------------------------------------------------------- 1 | select 2 | e.ename, 3 | e.sal, 4 | d.dname 5 | from emp e,dept d 6 | where e.deptno = d.deptno and e.sal > 2000 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_068.txt: -------------------------------------------------------------------------------- 1 | select 2 | e.ename, 3 | d.dname 4 | from emp e,dept d 5 | where e.deptno = d.deptno and e.job = 'MANAGER' -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_069.txt: -------------------------------------------------------------------------------- 1 | select 2 | d.dname 3 | from emp e,dept d 4 | where e.deptno = d.deptno and e.sal > 1500 5 | group by d.dname -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_070.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | e.ename, 3 | v.vehiclename 4 | FROM empvehicle ev JOIN vehicle v ON ev.vehicleid = v.vehicleid 5 | RIGHT JOIN emp e ON ev.empno = e.empno -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_071.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | i.itemcode, 3 | i.descr, 4 | q.sname 5 | FROM quotation q,item i 6 | WHERE q.itemcode = i.itemcode 7 | 8 | ========================OR WITHOUT USING JOINS=============== 9 | select 10 | itemcode, 11 | (select descr from item i where i.itemcode = q.itemcode) as descr, 12 | sname 13 | from quotation q 14 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_072.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | c.custid AS "Customer Id" , 3 | c.custname AS "Customer Name" 4 | FROM customer c,empdetails e 5 | WHERE c.CUSTNAME= e.EMPNAME AND c.EMAILID = e.EMAILID -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_073.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | i.itemcode, 3 | i.descr, 4 | i.category, 5 | q.quotedprice 6 | FROM item i,quotation q 7 | WHERE q.itemcode = i.itemcode AND q.qstatus = 'Accepted' 8 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_074.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | rs.roid, 3 | i.descr, 4 | i.itemtype, 5 | rs.unitprice 6 | FROM retailstock rs, item i 7 | WHERE rs.itemcode = i.itemcode AND rs.unitprice > 1500 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_075.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | i.ITEMCODE AS itemcode, 3 | qt.SNAME AS sname, 4 | SUM (o.qtyordered) AS totalquantity 5 | FROM orders o, quotation qt, item i 6 | WHERE o.quotationid = qt.quotationid AND qt.itemcode = i.itemcode 7 | GROUP BY i.ITEMCODE, qt.SNAME 8 | HAVING SUM(o.qtyordered) >= 100 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_076.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | i.itemcode, 3 | i.descr 4 | FROM item i, quotation qt 5 | WHERE i.itemcode = qt.itemcode AND i.price = qt.quotedprice 6 | GROUP BY i.itemcode,i.DESCR 7 | HAVING count(i.itemcode) > 1 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_077.txt: -------------------------------------------------------------------------------- 1 | SELECT q.sname, 2 | q.quotationid 3 | FROM quotation q,orders o 4 | WHERE q.QUOTATIONID = o.QUOTATIONID AND (o.DELIVEREDDATE - o.orderdate) <= 5 5 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_078.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | NVL(e.empname,'No Manager') AS empname, 3 | i.category, 4 | sum(rs.qtyavailable) AS totalquantity 5 | FROM empdetails e RIGHT JOIN retailoutlet r ON r.managerid = e.empid 6 | JOIN retailstock rs ON r.roid = rs.roid 7 | JOIN item i ON rs.itemcode = i.itemcode 8 | GROUP BY e.empname,i.CATEGORY -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_079.txt: -------------------------------------------------------------------------------- 1 | SELECT ro.location, 2 | c.CUSTTYPE, 3 | SUM(pb.QUANTITY) AS totalquantity 4 | FROM item i, customer c, retailoutlet ro, purchasebill pb 5 | WHERE ro.roid = pb.ROID AND pb.CUSTID = c.custid AND pb.itemcode = i.itemcode AND c.gender = 'M' 6 | AND i.ITEMTYPE IN ('Apparels','Computer') 7 | GROUP BY ro.location,c.CUSTTYPE 8 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_080.txt: -------------------------------------------------------------------------------- 1 | SELECT i.itemcode, 2 | i.descr, 3 | NVL(pb.BILLAMOUNT,0) AS billamount, 4 | NVL(pb.custid,0) AS custid 5 | FROM item i LEFT JOIN purchasebill pb ON pb.itemcode = i.itemcode 6 | WHERE i.ITEMTYPE = 'FMCG' 7 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_081.txt: -------------------------------------------------------------------------------- 1 | SELECT i.itemcode, 2 | i.descr, 3 | NVL(TO_CHAR(rs.qtyavailable),'N.A.') AS qtyavailable 4 | FROM item i LEFT JOIN retailstock rs ON i.itemcode = rs.itemcode 5 | AND rs.ROID = 'R1001' -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_082.txt: -------------------------------------------------------------------------------- 1 | SELECT emp.empid, 2 | emp.EMPNAME, 3 | ro.ROID, 4 | ro.LOCATION 5 | FROM empdetails emp RIGHT JOIN retailoutlet ro ON ro.roid = emp.WORKSIN -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_083.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | e2.EMPNAME, 3 | e2.designation, 4 | e2.emailid 5 | FROM empdetails e1 JOIN empdetails e2 ON e1.EMPNAME = 'George' AND e1.WORKSIN = e2.WORKSIN 6 | WHERE e2.EMPNAME != 'George' 7 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_084.txt: -------------------------------------------------------------------------------- 1 | SELECT c1.custid, 2 | c1.CUSTNAME 3 | FROM customer c1,customer c2 4 | WHERE c1.address =c2.address 5 | GROUP BY c1.CUSTNAME,c1.custid 6 | HAVING count(c1.address) > 1 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_085.txt: -------------------------------------------------------------------------------- 1 | SELECT c.CUSTNAME, 2 | pb.billamount 3 | FROM purchasebill pb, customer c 4 | WHERE pb.CUSTID = c.custid AND pb.BILLAMOUNT > 5000 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_086.txt: -------------------------------------------------------------------------------- 1 | SELECT ro.roid, 2 | count(i.QTYONHAND) AS "Number of items" 3 | FROM item i, retailstock ro 4 | WHERE ro.itemcode = i.itemcode 5 | GROUP BY ro.roid 6 | 7 | -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_087.txt: -------------------------------------------------------------------------------- 1 | SELECT rs.itemcode, 2 | i.descr, 3 | ro.LOCATION, 4 | rs.qtyavailable 5 | FROM item i,retailoutlet ro, retailstock rs 6 | WHERE i.itemcode = rs.itemcode AND rs.roid = ro.roid AND i.itemtype = 'Apparels' -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_088.txt: -------------------------------------------------------------------------------- 1 | SELECT i.itemcode, i.descr, NVL(q.quotationid, 'No quotation received') AS QUOTATIONID 2 | FROM item i LEFT JOIN quotation q 3 | ON i.ITEMCODE = q.itemcode -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_089.txt: -------------------------------------------------------------------------------- 1 | SELECT ro.itemcode,i.descr, roid, ro.qtyavailable 2 | FROM retailstock ro, item i 3 | WHERE ro.itemcode = i.itemcode -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_090.txt: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT i.descr, i.itemtype, pb.billamount 2 | FROM retailstock ro, item i, purchasebill pb 3 | WHERE ro.itemcode = i.itemcode AND pb.itemcode = i.itemcode AND pb.roid = 'R1001' -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_091.txt: -------------------------------------------------------------------------------- 1 | SELECT c.custid, c.custname, c.custtype FROM customer c 2 | WHERE c.custtype = 3 | (SELECT custtype FROM customer WHERE custid = 2004) 4 | AND c.custid != 2004 -------------------------------------------------------------------------------- /Day-5/Assignments/Solution_092.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | i.itemtype, 3 | i.descr, 4 | NVL(q.quotationid, 'No quotation received') AS "Available Quotation number" 5 | FROM item i LEFT JOIN quotation q 6 | ON i.itemcode = q.itemcode 7 | WHERE i.itemtype IN ('Computer', 'FMCG') -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_40.txt: -------------------------------------------------------------------------------- 1 | SELECT sid, sname, location FROM salesman WHERE location LIKE '%o%'AND sname LIKE '%e%' 2 | UNION ALL 3 | SELECT sid, sname, location FROM salesman WHERE location LIKE '%a%' AND sname LIKE '%a%' 4 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_41.txt: -------------------------------------------------------------------------------- 1 | select prodid,pdesc,category,discount from product where discount < 10 2 | union all 3 | select prodid,pdesc,category,discount from product where category = 'Sports' 4 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_42.txt: -------------------------------------------------------------------------------- 1 | select prodid,pdesc,category,discount from product where discount < 10 2 | union 3 | select prodid,pdesc,category,discount from product where category = 'Sports' 4 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_43.txt: -------------------------------------------------------------------------------- 1 | select 'S' as type, sid as id, sname as details from salesman 2 | union all 3 | select 'P' as type, prodid as id, category as details from product -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_44.txt: -------------------------------------------------------------------------------- 1 | select emp.id as id,emp.ename as ename,emp.dept as dept, comp.compid as compid,comp.make as make 2 | from employee emp, computer comp 3 | where emp.compid = comp.compid -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_45.txt: -------------------------------------------------------------------------------- 1 | select emp.id as id,emp.ename as ename, comp.compid as compid,comp.make as make 2 | from employee emp, computer comp 3 | where emp.compid = comp.compid and comp.model in ('Edge','Precision') -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_46.txt: -------------------------------------------------------------------------------- 1 | SELECT e.dept,COUNT(c.make) as "NUMBER OF COMPUTERS" 2 | FROM employee e INNER JOIN computer c 3 | ON e.compid = c.compid WHERE c.make = 'Dell' 4 | GROUP BY e.dept -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_47.txt: -------------------------------------------------------------------------------- 1 | select s.saleid, s.sldate 2 | from salesman sm, sale s 3 | where sm.location = 'London' and sm.sid = s.sid -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_48.txt: -------------------------------------------------------------------------------- 1 | select s1.sid,s1.sname,s1.location 2 | from salesman s1, salesman s2 3 | where s1.location = s2.location and s1.sid != s2.sid -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_49.txt: -------------------------------------------------------------------------------- 1 | select slm.sname,sl.saleid 2 | from salesman slm left outer join sale sl 3 | on slm.sid = sl.sid -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_50.txt: -------------------------------------------------------------------------------- 1 | select slm.sid, slm.sname, sum(p.price*sd.quantity) as tamount, sum((p.price*sd.quantity)*(p.discount/100)) as tdiscount 2 | from salesman slm, product p, sale s, saledetail sd 3 | where slm.sid = s.sid and sd.saleid = s.saleid and p.prodid = sd.prodid 4 | 5 | group by slm.sid,slm.sname 6 | order by tdiscount desc, tamount desc -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_51.txt: -------------------------------------------------------------------------------- 1 | select sd.saleid, sd.prodid, s.sid, slm.sname 2 | from salesman slm, product p, sale s, saledetail sd 3 | where sd.saleid = s.saleid and sd.prodid = p.prodid and s.sid = slm.si -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_52.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | slm.sid, 3 | slm.sname, 4 | NVL(SUM(p.price * sd.quantity),0) AS tamount, 5 | NVL(SUM(p.price * sd.quantity*p.discount/100),0) AS tdiscount 6 | 7 | FROM salesman slm LEFT JOIN sale s ON s.sid = slm.sid 8 | left JOIN saledetail sd ON sd.saleid = s.saleid 9 | left JOIN product p ON sd.prodid = p.prodid 10 | GROUP BY slm.sid,slm.sname -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_53.txt: -------------------------------------------------------------------------------- 1 | SELECT 2 | slm.location, 3 | p.category, 4 | sum(sd.quantity) as "Total Quantity" 5 | 6 | FROM salesman slm , sale s ,saledetail sd , product p 7 | where s.sid = slm.sid and sd.saleid = s.saleid and sd.prodid = p.prodid 8 | group by slm.location, p.category 9 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_54.txt: -------------------------------------------------------------------------------- 1 | select e.ename, e.dept, NVL(c.model,'Not allocated' ) as model 2 | from employee e left join computer c 3 | on e.compid = c.compid -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_55.txt: -------------------------------------------------------------------------------- 1 | select e.id, e.ename, e.dept, c.model 2 | from employee e full join computer c 3 | on e.compid = c.compid 4 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_56.txt: -------------------------------------------------------------------------------- 1 | select e.id, 2 | e.ename, 3 | m.id as mgrid, 4 | m.ename as mgrname, 5 | ce.model as e_model, 6 | cm.model M_model 7 | from employee e, computer ce, computer cm, employee m 8 | where e.compid = ce.compid and e.manager = m.id and m.compid = cm.compid 9 | -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_57.txt: -------------------------------------------------------------------------------- 1 | select sid, sname from salesman 2 | where sid not in 3 | (select sid from sale) -------------------------------------------------------------------------------- /Day-5/Excercises/Excer_58.txt: -------------------------------------------------------------------------------- 1 | select p1.prodid,p1.category,p1.price 2 | from product p1, product p2 3 | where p1.price = p2.price and p1.prodid != p2.prodid -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_093.txt: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT i.itemcode, i.itemtype, i.descr, i.category 2 | FROM item i , purchasebill pb 3 | WHERE i.itemcode = pb.itemcode 4 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_094.txt: -------------------------------------------------------------------------------- 1 | SELECT itemcode, itemtype, descr, category 2 | FROM item 3 | WHERE price IN 4 | ( 5 | SELECT min(quotedprice) FROM quotation WHERE qstatus = 'Rejected' 6 | ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_095.txt: -------------------------------------------------------------------------------- 1 | SELECT i.itemcode, i.descr 2 | FROM item i, quotation q 3 | WHERE i.itemcode = q.ITEMCODE AND q.qstatus IN ('Rejected','Closed') AND q.quotedprice IN 4 | ( 5 | SELECT max(q1.quotedprice)FROM quotation q1 WHERE q1.qstatus IN ('Rejected','Closed') 6 | ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_096.txt: -------------------------------------------------------------------------------- 1 | SELECT i.itemcode, i.descr,i.price 2 | FROM item i, quotation q 3 | WHERE i.itemcode = q.ITEMCODE AND q.qstatus IN ('Rejected','Closed') AND q.quotedprice IN 4 | ( 5 | SELECT max(q1.quotedprice)FROM quotation q1 WHERE q1.qstatus IN ('Rejected','Closed') 6 | ) 7 | 8 | *******************************OR****************************** 9 | SELECT itemcode, descr, price 10 | FROM item 11 | WHERE price = ( 12 | SELECT max(price) AS maxx FROM item 13 | WHERE price < 14 | ( 15 | SELECT max(price) AS maxx FROM item 16 | ) 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_097.txt: -------------------------------------------------------------------------------- 1 | SELECT empid, empname, designation 2 | FROM empdetails 3 | WHERE empid IN 4 | ( 5 | SELECT managerid FROM retailoutlet) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_098.txt: -------------------------------------------------------------------------------- 1 | SELECT e.ename,e.job FROM emp e 2 | WHERE empno IN 3 | (SELECT ev.empno FROM empvehicle ev) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_099.txt: -------------------------------------------------------------------------------- 1 | SELECT e1.ename FROM emp e1 2 | WHERE e1.sal = 3 | (SELECT max(e2.sal) FROM emp e2) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_100.txt: -------------------------------------------------------------------------------- 1 | SELECT emp.empno, emp.ename FROM emp 2 | WHERE emp.empno IN 3 | ( 4 | SELECT e1.EMPNO FROM empvehicle e1,empvehicle e2 5 | WHERE e1.vehicleid = e2.vehicleid AND e1.EMPNO != e2.EMPNO 6 | GROUP BY e1.empno 7 | ) 8 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_101.txt: -------------------------------------------------------------------------------- 1 | SELECT e1.empno, e1.ename, e1.deptno FROM emp e1,emp e2 2 | WHERE e1.deptno = e2.deptno AND e2.ename = 'SMITH' AND e1.ename != e2.ename -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_102.txt: -------------------------------------------------------------------------------- 1 | SELECT q1.itemcode, i.descr, q1.qdate FROM quotation q1,item i 2 | WHERE i.itemcode = q1.itemcode AND q1.quotedprice < 3 | ( 4 | SELECT max(q2.quotedprice) FROM quotation q2 5 | WHERE q2.qdate = q1.qdate AND q1.quotationid != q2.quotationid 6 | GROUP BY q2.qdate 7 | ) 8 | 9 | =========================OR=================================== 10 | 11 | SELECT i.itemcode, i.descr, q3.qdate FROM quotation q3, item i 12 | WHERE i.itemcode =q3.itemcode AND q3.quotedprice IN 13 | (SELECT quotedprice FROM quotation q2 14 | WHERE q3.qdate = q2.qdate AND q2.quotedprice < 15 | (SELECT max(quotedprice) FROM quotation q1 16 | WHERE q1.qdate = q2.qdate GROUP BY qdate) ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_103.txt: -------------------------------------------------------------------------------- 1 | SELECT pb1.billid, pb1.itemcode FROM purchasebill pb1 2 | WHERE pb1.BILLAMOUNT <= 3 | ( 4 | SELECT sum(billamount)/count(roid) FROM purchasebill pb2 5 | WHERE pb2.roid = pb1.roid 6 | GROUP BY roid 7 | ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_104.txt: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT sname, i.itemcode, descr 2 | FROM item i, quotation q 3 | WHERE i.itemcode = q.ITEMCODE 4 | AND q.quotedprice < 5 | (SELECT max(q1.quotedprice) FROM quotation q1 WHERE q.itemcode = q1.itemcode AND q.sname <> q1.sname) 6 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_105.txt: -------------------------------------------------------------------------------- 1 | SELECT empid, empname, designation, salary FROM empdetails e2 2 | WHERE e2.salary = 3 | ( 4 | SELECT max(e1.salary) FROM empdetails e1 5 | WHERE e1.designation = e2.designation 6 | GROUP BY e1.designation 7 | ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_106.txt: -------------------------------------------------------------------------------- 1 | SELECT c.custid, c.custname FROM customer c 2 | WHERE NOT EXISTS (SELECT 1 FROM purchasebill WHERE c.CUSTID = custid) 3 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_107.txt: -------------------------------------------------------------------------------- 1 | SELECT BillId, PB.ItemCode, PB.CustId, BillAmount, BillDate, Quantity 2 | FROM PurchaseBill PB 3 | WHERE pb.custid = (SELECT custid FROM customer c WHERE custtype = 'Privileged' AND c.CUSTID = pb.custid) 4 | AND pb.itemcode = (SELECT itemcode FROM item i WHERE itemtype = 'FMCG' AND i.itemcode = pb.itemcode) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_108.txt: -------------------------------------------------------------------------------- 1 | SELECT custid, custname FROM customer 2 | WHERE custid IN 3 | ( 4 | SELECT DISTINCT custid FROM purchasebill 5 | ) 6 | -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_109.txt: -------------------------------------------------------------------------------- 1 | SELECT e2.empno, e2.ename FROM emp e2 2 | WHERE e2.sal > 3 | ( 4 | SELECT avg(sal) FROM emp e1 5 | WHERE e1.deptno = e2.deptno 6 | GROUP BY deptno 7 | ) -------------------------------------------------------------------------------- /Day-6/Assignments/Solution_110.txt: -------------------------------------------------------------------------------- 1 | 2 | DELETE FROM empvehicle where empno IN 3 | ( 4 | SELECT empno FROM emp WHERE sal in 5 | (SELECT max(sal) FROM emp 6 | GROUP BY deptno ) 7 | ) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_59.txt: -------------------------------------------------------------------------------- 1 | SELECT saleid, sldate FROM sale 2 | WHERE sldate = 3 | (SELECT MAX(sldate) FROM sale) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_60.txt: -------------------------------------------------------------------------------- 1 | select sname from salesman where sid in 2 | (select sid from sale group by sid having count(sid) >= 2) 3 | -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_61.txt: -------------------------------------------------------------------------------- 1 | select prodid, pdesc from product where prodid = 2 | ( 3 | select prodid from saledetail group by prodid having sum(quantity) = 4 | ( 5 | select min(sum(quantity)) from saledetail group by prodid )) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_62.txt: -------------------------------------------------------------------------------- 1 | SELECT sm.sid, sm.sname, sm.location 2 | FROM salesman sm, sale s 3 | WHERE sm.sid = s.sid 4 | AND s.saleid IN 5 | ( 6 | SELECT sd.saleid 7 | FROM product p,saledetail sd 8 | WHERE p.prodid = sd.prodid 9 | GROUP BY sd.saleid 10 | HAVING sum(p.price*sd.quantity*(1-(p.discount/100))) > 11 | ( 12 | select avg(sum(p.price*sd.quantity*(1-(p.discount/100)))) 13 | FROM product p,saledetail sd 14 | WHERE p.prodid = sd.prodid 15 | GROUP BY sd.prodid 16 | ) 17 | ) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_63.txt: -------------------------------------------------------------------------------- 1 | SELECT prodid, category, pdesc, price 2 | FROM product p1 WHERE price IN 3 | ( 4 | SELECT MAX(price) FROM product p2 5 | WHERE p1.category = p2.category 6 | ) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_64.txt: -------------------------------------------------------------------------------- 1 | SELECT sname FROM salesman sl 2 | WHERE sl.sid NOT IN 3 | (SELECT sid FROM sale s) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_65.txt: -------------------------------------------------------------------------------- 1 | SELECT sname FROM salesman sl 2 | WHERE sl.sid = 3 | (SELECT sid FROM sale s 4 | WHERE s.sldate LIKE '%JUN-15' 5 | group by sid 6 | having count(sid) >=1) -------------------------------------------------------------------------------- /Day-6/Excercises/Excer_66.txt: -------------------------------------------------------------------------------- 1 | SELECT sm.sid,sm.sname,sm.location 2 | FROM salesman sm, sale s,saledetail sd ,product p 3 | WHERE sm.sid=s.sid AND s.saleid=sd.saleid AND p.prodid=sd.prodid 4 | GROUP BY sm.sid,sm.sname,sm.location 5 | HAVING sum(price*quantity*(1-discount/100))> 6 | ( 7 | SELECT avg(sum(price*quantity*(1-discount/100))) 8 | FROM sale s1, saledetail sd1, product p1, salesman sm1 9 | WHERE s1.saleid=sd1.saleid 10 | AND p1.prodid=sd1.prodid 11 | AND s1.sid=sm1.sid 12 | AND sm.location=sm1.location 13 | GROUP BY s1.sid 14 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DBMS 2 | Database Management System provides knowledge about MySql. 3 | 4 | Creating Table 5 | Updating Table 6 | Insterting into Table 7 | Deleting from Table 8 | Drop Table 9 | Altering Table 10 | 11 | writing queries to get req result from given tabular Da 12 | --------------------------------------------------------------------------------