MENT CS CLASSPART-5-Final
MENT CS CLASSPART-5-Final
(iv) Create the below tables with appropriate data type and required Primary key.
(v) Write the command to view all tables under current database.
(vi) Write the commands to view the structure of the above created tables.
DESC SALES ;
Program 27: Write the SQL statements for the following:
(i) Write the necessary commands to insert the following in the previously create tables:
(ii) Write the command to view all contents of the above tables.
(iii) What is degree and cardinality of the above created tables respectively?
(iv) Write SQL statement for display all computer product name and price with type as input.
(v) Write SQL statement to display distinct company from table computer.
(vi) Write SQL statement to display Product name with their respective quantity sold during quarter 1.
(vi) SELECT COMPUTER.PROD_NAME, SALES.QTY_SOLD FROM COMPUTER, SALES WHERE SALES.QUARTER=1 AND
COMPUTER.PROD_ID=SALES.PROD_ID ;
Program 28: Write the outputs of the SQL queries (i) to (vii) based on the relations COMPUTER and SALES given
below:
Table: COMPUTER Table: SALES
PROD_ID PROD_NAME PRICE COMPANY TYPE PROD_ID QTY_SOLD QUARTER
P001 MOUSE 200 LOGITECH INPUT P002 4 1
P002 LASER PRINTER 4000 CANON OUTPUT P003 2 2
P003 KEYBOARD 500 LOGITECH INPUT P001 3 2
P004 JOYSTICK 1000 IBALL INPUT P004 2 1
P005 SPEAKER 1200 CREATIVE OUTPUT P007 3 2
P006 DESKJET PRINTER 4300 CANON OUTPUT
(ii) SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY HAVING COUNT(COMPANY) > 1 ;
(iii) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES S WHERE C.PROD_ID=S. PROD_ID AND TYPE =
'INPUT' ;
(iv) SELECT PROD_NAME, COMPANY, QUARTER FROM COMPUTER C, SALES S WHERE C.PROD_ID=S.PROD_ID ;
(v) SELECT PROD_NAME, COMPANY, (PRICE*QTY_SOLD) AS 'TOTAL SALES' FROM COMPUTER C, SALES S WHERE
C.PROD_ID=S.PROD_ID ORDER BY C.PROD_ID ;
(vi) SELECT COMPANY, SUM(PRICE), TYPE FROM COMPUTER GROUP BY COMPANY ORDER BY TYPE DESC ;
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
Program 29: Write the outputs of the SQL queries (i) to (v) based on the relations COMPUTER and SALES given
below:
(i)
(ii)
(iii)
(iv)
(v)
Program 30: Write the SQL statements or SQL queries with output (if any) for (i) to (x) based on the relations
COMPUTER and SALES given below:
(i) Add a new column GST (%) after PRICE in the table COMPUTER and make GST (%) default value as 18.
(iv) Update the company name of all printers from CANON to EPSON.
(v) Display all records available in the table Computer after previous modifications.
(vi) Display all product name, GST and respective price after GST rounded up to 2 decimal place.
(i) ALTER TABLE COMPUTER ADD `GST (%)` INTEGER DEFAULT 18 AFTER PRICE ;
(ii)
(i) SELECT DESIGNATION, COUNT(*) FROM ADMIN GROUP BY DESIGNATION HAVING COUNT(*) < 2 ;
(iii) SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >= 8 ORDER BY TEACHER ;
(vii) SELECT SUBJECT, COUNT(*) AS "NO. OF TECHERS", SUM(EXPERIENCE) AS "TOTAL YEARS OF EXPERIENCE"
FROM SCHOOL GROUP BY SUBJECT ;
(viii) SELECT SUBJECT, GENDER, COUNT(*) FROM SCHOOL S, ADMIN A WHERE S.CODE = A.CODE GROUP BY
SUBJECT, GENDER ;
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
(viii)