0% found this document useful (0 votes)
19 views

Record SQL (1, 2, 3)

Uploaded by

pjotr.765
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Record SQL (1, 2, 3)

Uploaded by

pjotr.765
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PGM NO: 1

DATE: SQL COMMAND – 1

AIM:
To create a table GYM and to apply various SQL commands for the
table and find the output for the queries.
Table: GYM

TABLE CREATION:
CREATE TABLE GYM(MCODE INT PRIMARY KEY, MNAME CHAR(20),
GENDER CHAR(6), AGE INT, FEEGIVEN INT, TYPE VARCHAR(10), DTADMIT
DATE);
RECORD INSERTION:
INSERT INTO GYM VALUES(201, “AMIT”, “MALE”, 35, 6000, “QUARTERLY”,
“2016-01-23”);
DISPLAY ALL RECORDS:
SELECT * FROM GYM;
SQL QUERIES:
(i) To display mname, age, feegiven of those members whose fee is above
12000.
SELECT MNAME, AGE, FEEGIVEN FROM GYM
WHERE FEEGIVEN >12000;

1
(ii) To display mcode, mname, age of all female members of the gym in
descending order of their age.
SELECT MCODE, MNAME, AGE FROM GYM
WHERE GENDER="FEMALE" ORDER BY AGE DESC;
(iii) To list names of members and their date of admission of those members
who joined after 31st December 2015.
SELECT MNAME, DTADMIT FROM GYM WHERE DTADMIT >
"2015-12-31";
(iv) To count the number of members of gym of each type.
SELECT TYPE, COUNT(*) FROM GYM GROUP BY TYPE;
(v) To display the mname, feegiven of all those members of the gym whose
age is less than 40 and monthly type members of gym.
SELECT MNAME, FEEGIVEN FROM GYM
WHERE AGE < 40 AND TYPE = "MONTHLY";
(vi) To display the type along with maximum and minimum fees of each type.
SELECT TYPE, MAX(FEEGIVEN), MIN(FEEGIVEN) FROM GYM
GROUP BY TYPE;
(vii) To display types of memberships available, without repetition.
SELECT DISTINCT TYPE FROM GYM;
(viii) To display names of members who have the substring “MIT” anywhere in
their names.
SELECT MNAME FROM GYM WHERE MNAME LIKE "%MIT%";
(ix) To display the type along with sum and average of feegiven for each type.
SELECT TYPE, SUM(FEEGIVEN), AVG(FEEGIVEN) FROM GYM
GROUP BY TYPE;
(x) To display type along with number of male members whose age is above
30, in each type.
SELECT TYPE, COUNT(*) FROM GYM
WHERE GENDER = "MALE" AND AGE >30 GROUP BY TYPE;
RESULT:
The above SQL queries were executed and the output was verified.

2
PGM NO: 2
DATE: SQL COMMAND – 2

AIM:
To create a table BILL and to apply various SQL commands for the table
and find the output for the queries.
Table: BILL

TABLE CREATION:
CREATE TABLE BILL (ORD_ID INT PRIMARY KEY, CUST_ID CHAR(4), ITEM
VARCHAR(20), ORD_DATE DATE, QTY INT,PRICE FLOAT);
INSERT RECORDS:
INSERT INTO BILL VALUES (7002, 'C007', 'Pizza', '2007-11-20', 1, 249.50);
DISPLAY ALL RECORDS:
SELECT * FROM BILL;
SQL QUERIES:
(i) Count the number of customers who have ordered item worth more than
1700. (Total amount is calculated as qty* price)
SELECT COUNT(CUST_ID) FROM BILL
WHERE QTY*PRICE>1700;
(ii) Display the count of each item from BILL table.
SELECT ITEM, COUNT(*) FROM BILL
GROUP BY ITEM;

3
(iii) Display the item, ord_date, qty for those quantities which are more
than 3.
SELECT ITEM, ORD_DATE, QTY FROM BILL
WHERE QTY>3;
(iv) Display the cust_id and total amount (qty*price) of items purchased by each
customer.
SELECT CUST_ID, SUM(PRICE*QTY) FROM BILL
GROUP BY CUST_ID;
(v) Display the cust_id, order date and item in descending order of order
date and the item are either brownie or ice cream.
SELECT CUST_ID, ORD_DATE, ITEM FROM BILL
WHERE ITEM="ICE CREAM" OR ITEM = "BROWNIE"
ORDER BY ORD_DATE DESC;
(vi) Display item name and total amount (qty * price) calculated itemwise.
SELECT ITEM, SUM(QTY*PRICE) AS TOTAL_AMOUNT
FROM BILL GROUP BY ITEM;
(vii) To display the customer id, item and price of those items whose
names contain either “e” or “c”.
SELECT CUST_ID, ITEM, PRICE FROM BILL
WHERE ITEM LIKE "%E%" OR ITEM LIKE "%C%";
(viii) To display the name of unique items.
SELECT DISTINCT (ITEM) FROM BILL;
(ix) To display the cutomer id, item and price of the item if price is either
above 150 or below 250 (Both the values inclusive).
SELECT CUST_ID, ITEM, PRICE FROM BILL
WHERE PRICE BETWEEN 150 AND 250;
(x) To display the sum of price of the items “Pizza”, “Pasta” and “Garlic
bread”.
SELECT SUM(PRICE) FROM BILL
WHERE ITEM IN ("PIZZA", "PASTA", "GARLIC BREAD");

RESULT:
The above SQL queries were executed and the output was verified.

4
PGM NO: 3
DATE: SQL COMMAND – 3

AIM:
To create the tables SUPPLIER and PRODUCT and to apply various SQL
commands and find the output of the queries.
Table: SUPPLIER

Table: PRODUCT

TABLE CREATION: (SUPPLIER)


CREATE TABLE SUPPLIER(SCODE CHAR(3) PRIMARY KEY, SNAME
VARCHAR(20), CITY VARCHAR(15));
TABLE CREATION: (PRODUCTS)
CREATE TABLE PRODUCTS(PIN INT PRIMARY KEY, PNAME CHAR(20), QTY
INT, PRICE DECIMAL(10,2), COMPANY CHAR(20),SCODE CHAR(3));
RECORD INSERTION: (SUPPLIER)
INSERT INTO SUPPLIER VALUES('S01', 'GET ALL INC', 'KOLKATTA');
RECORD INSERTION: (PRODUCTS)
INSERT INTO PRODUCTS VALUES (101, 'DIGITAL CAMERA 14X', 11, 12000,
'RENIX', 'S01');
DISPLAY ALL RECORDS: (SUPPLIER)
SELECT * FROM SUPPLIER;
DISPLAY ALL RECORDS: (PRODUCTS)
SELECT * FROM PRODUCTS;

5
SQL QUERIES:
(i) To display the details of the products in ascending order of product
names.
SELECT * FROM PRODUCTS
ORDER BY PNAME;
(ii) To display product name and price of all those products whose price is in
the range of 10000 and 15000 (both values inclusive).
SELECT PNAME, PRICE FROM PRODUCTS
WHERE PRICE BETWEEN 10000 AND 15000;
(iii) To display the number of products which are supplied by each supplier.
SELECT SCODE, COUNT(*) FROM PRODUCTS
GROUP BY SCODE;
(iv) To display the price, products name and quantity of those products
which have quantity more than 50.
SELECT PRICE, PNAME, QTY FROM PRODUCTS
WHERE QTY >50;
(v) To display the name and city of those supplier who are either from Delhi
or Chennai.
SELECT SNAME, CITY FROM SUPPLIER
WHERE CITY IN ('DELHI', 'CHENNAI');
(vi) To display the name of the products and company in descending order of
company names.
SELECT PNAME, COMPANY FROM PRODUCTS
ORDER BY COMPANY DESC;
(vii) To display the maximum price along with the product name and
supplier name for each supplier.
SELECT MAX(PRICE), PNAME, SNAME FROM PRODUCTS P, SUPPLIER S
WHERE P.SCODE=S.SCODE GROUP BY P.SCODE;
(viii) To display the supplier code and sum of price of products, where the
number of products by the supplier is more than 1.
SELECT S.SCODE, SUM(PRICE)
FROM PRODUCTS P, SUPPLIER S

6
WHERE P.SCODE = S.SCODE
GROUP BY P.SCODE HAVING COUNT(*) > 1;
(ix) To display the output of the natural join on both the tables.
SELECT * FROM SUPPLIER NATURAL JOIN PRODUCTS;
(x) To display the output of equijoin on both the tables.
SELECT * FROM SUPPLIER S, PRODUCTS P
WHERE P.SCODE=S.SCODE;
RESULT:
The above SQL queries were executed and the output was verified.

You might also like