0% found this document useful (0 votes)
47 views7 pages

SQL Question - Answer For Xii For Practical

The document contains SQL commands for various queries related to COMPANY, CUSTOMER, SCHOOL, ADMIN, WATCHES, SALE, SHOP, and ACCESSORIES tables. It includes commands for displaying, updating, and aggregating data, as well as programming solutions for stack operations and string manipulation. Each question is followed by SQL statements and expected outputs for specific queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views7 pages

SQL Question - Answer For Xii For Practical

The document contains SQL commands for various queries related to COMPANY, CUSTOMER, SCHOOL, ADMIN, WATCHES, SALE, SHOP, and ACCESSORIES tables. It includes commands for displaying, updating, and aggregating data, as well as programming solutions for stack operations and string manipulation. Each question is followed by SQL statements and expected outputs for specific queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 1:

Write SQL commands for the queries (i) to (iv) and output for (v) & (viii) based on a table
COMPANY and CUSTOMER.

1. To display those company name which are having prize less than 30000.
2. To display the name of the companies in reverse alphabetical order.
3. To increase the prize by 1000 for those customer whose name starts with „S?
4. To add one more column total price with decimal] 10,2) to the table customer
5. SELECT COUNT (*), CITY FROM COMPANY GROUP BY CITY;
6. SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10;
7. SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;
8. SELECT PRODUCTNAME,CITY, PRICE
FROM COMPANY, CUSTOMER WHERE
COMPANY. CID=CUSTOMER.CID AND
PRODUCTNAME=”MOBILE”;

Answer:

1. SELECT NAME FROM COMPANY WHERE COMPANY.CID=CUSTOMER. CID AND


PRICE < 30000;
2. SELECT NAME FROM COMPANY ORDER BY NAME DESC;
3. UPDATE CUSTOMER
SET PRICE = PRICE + 1000
WHERE NAME LIKE ‘S%’;
4. ALTER TABLE CUSTOMER
ADD TOTALPRICE DECIMAL(10,2);

5.
6. 50000,70000
7. 11
8.

Question 2:
Consider the following tables SCHOOL and ADMIN and answer this question :

Write SQL statements for the following:

1. To display TEACHERNAME, PERIODS of all teachers whose periods are more than 25.
2. To display all the information from the table SCHOOL in descending order of experience.
3. To display DESIGNATION without duplicate entries from the table ADMIN.
4. To display TEACHERNAME, CODE and corresponding DESIGNATION from tables
SCHOOL and ADMIN of Male teachers.

Answer:

1. SELECT TEACHERNAME, PERIODS


FROM SCHOOL WHERE PERIODS>25:
2. SELECT * FROM SCHOOL;
3. SELECT DISTINCT DESIGNATION FROM ADMIN;
4. SELECT TEACHERNAME.CODE
DESIGNATION FROM
SCHOOL.CODE = ADMIN.CODE
WHERE GENDER = MALE;

Question 3:
Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the tables
Watches’ and Sale given below.

1. TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME ENDS WITH
‘TIME’
2. TO DISPLAY WATCH’S NAME AND PRICE OF THOSE WATCHES WHICH HAVE PRICE
RANGE IN BE-TWEEN 5000-15000.
3. TO DISPLAY TOTAL QUANTITY IN STORE OF UNISEX TYPE WATCHES.
4. TO DISPLAY WATCH NAME AND THEIR QUANTITY SOLD IN FIRST QUARTER;
5. SELECT MAX (PRICE), MIN(QTY_STORE) FROM WATCHES;
6. SELECT QUARTER, SUM(QTY SOLD) FROM SALE GROUP BY QUARTER;
7. SELECT WATCH_NAME, PRICE, TYPE FROM WATCHES W, SALE S WHERE W.
WAT£H1D!=S.WATCHID; (viii) SELECT WATCH_NAME, QTYSTORE, SUM (QTY_SOLD),
QTY_STORESUM (QTYSOLD) “STOCK” FROM WATCHES W, SALE S WHERE W.
WATCHID = S.WATCHID GROUP BY S.WATCHID;

Answer:

1. SELECT * FROM WATCHES WHERE WATCH_NAME LIKE ‘%TIME’


(Vi mark for SELECT query) (Vi mark for where clause)
2. SELECT WATCH_NAME, PRICE WATCH WHERE PRICE BETWEEN 5000 AND 15000;
(Vi mark for SELECT query) (Vz mark for where clause)
3. SELECT SUM (QTY STORE) FROM WATCHES WHERE TYPE LIKE ‘UNISEX’;
(Vz mark for SELECT query) (Vi mark for where clause)
4. SELECT WATCHNAME, QTY SOLD FROM WATCHES W,SALE S WHERE W. WATCHID
= S. WATCHID
AND QUARTER = 1;

Question 4:
Answer the questions (a) and (b) on the basis of the following tables SHOP and ACCESSORIES.

(a) Write the SQL queries:

1. To display Name and Price of all the Accessories in ascending order of their Price.
2. To display Id and SName of all Shop located in Nehru Place.
3. To display Minimum and Maximum Price of each Name of Accessories.
4. To display Name, Price of all Accessories and their respective SName where they are
available.
(b) Write the output of the following SQL

1. SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE> =5000;


2. SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA;
3. SELECT COUNT (DISTINCT AREA) FROM SHOPPE;
4. SELECT NAME, PRICE*0.05 DISCOUNT FROM ACCESSORIES WHERE SNO IN
(‘S02‘,S03‘);

Answer:
(a)

1. SELECT Name, Price FROM ACCESSORIES ORDER BY Price Asc;


2. SELECT ID SName FROM SHOP WHERE Area=”Nehru Place”;
3. SELECT Name, max (Price); min(Price) FROM ACCESSORIES, Group By Name;
4. SELECT Name,price, Sname FROM
ACCESSORIES, SHOP WHERE SHOE
ID=ACCESSORIES.ID;

(b)
Q. Write a program that depending upon user's choice, either
pushes or pops an element in a stack the elements are shifted
towards right so that top always remains at 0th (zero) index.
SOLUTION:
stack = [ ]
while True :
com = input("Enter ( Push or Pop ) : ")

if com == "push" or com == "Push" :


num = int(input("Enter a number : "))
stack.insert(0,num)

elif len(stack) == 0 :
print("Underflow")

elif com == "pop" or com == "Pop" :


stack.pop(0)
print("Your Stack :-",stack)

yes = input ("Enter ( Yes or no ) : ")

if yes == "No" or yes == "no":


print("Thank you !!!!")
break

Q. A line of text is read from the input terminal into a stack. Write a program to output the
string in reverse order, each character appearing twice. (e.g., the string a b c d e should be
changed to ee dd cc bb aa)

SOLUTON:

line = input("Enter a line : ")


stack = [ ]
for i in line :
stack.append(i+i)

stack.reverse()

for j in stack :
print( j , end=" ")

You might also like