0% found this document useful (0 votes)
48 views13 pages

MYSQL QUESTIONS

Mysql

Uploaded by

arpityada22
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)
48 views13 pages

MYSQL QUESTIONS

Mysql

Uploaded by

arpityada22
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/ 13

MYSQL QUESTIONS

Q-1) Write SQL query to create table named `purchase` as given


below with suitable datatype and constrains.

Perform the following operations on the table `purchase`:-


1. Display gender wise highest marks.
2. Display city wise lowest marks.
3. Display total number of male and female students.

Q-2) Write SQL query to create table named `cloth` as given


below with suitable datatype and constrains.

Perform the following operations on the table `cloth`:-


1. Write a query to display cloth names in lower case.
2. Write a query to display the lowest price of the cloths.
3. Write a query to count total number of cloths purchased of
medium size.
Q-3) Write SQL query to create table as given below with suitable
datatype and constrains.

Q-4) Consider table given in Q-3, write SQL query to display the
records in decreasing order of price.

Q-5) Consider table given in Q-2, write SQL query to display


month name of DOP and 30% of price of each row.

Q-6) Consider table given in Q-1 and write SQL queries for the
following,
1. To get number of students in each class.
2. To get names of all students whose name ends with “ek”.
3. To subtract 10 marks of each student whose marks is 430,
470 or 360.

Q-7) Consider table given in Q-2 and write SQL queries for the
following,
1. To fetch last 2 characters from the CCODE column.
2. To display the price divided by 44 rounded up to 3 decimal
places.
3. To display 3 characters from 2nd place from the column
COLOR.
Q-8) Write SQL query to create table `store` as given below with
suitable datatype and constrains.

1. To display names of stores along with Sales Amount of those


stores that are located in Mumbai.
2. To display the details of store in alphabetical order of name.
3. To display the City and the number of stores located in that
City, only if number of stores is more than 2.
ANSWERS
BASIC SETUP
CREATE DATABASE ip_project;
USE ip_project;
SHOW DATABASES;

ANSWER 1
CREATE TABLE purchase (`Roll No.` INT PRIMARY KEY, Name
VARCHAR(255), Class VARCHAR(30), Gender VARCHAR(20), City
VARCHAR(255), Marks INT);

INSERT INTO purchase VALUES


(1, "Abhishek", "XI", "M", "Agra", 430),
(2, "Prateek", "XII", "M", "Mumbai", 440),
(3, "Sneha", "XI", "F", "Agra", 470),
(4, "Nancy", "XII", "F", "Mumbai", 492),
(5, "Himanshu", "XII", "M", "Delhi", 360),
(6, "Anchal", "XI", "F", "Dubai", 256),
(7, "Mehar", "X", "F", "Moscow", 324),
(8, "Nishant", "X", "M", "Moscow", 429);

1. SELECT Gender, MAX(Marks) FROM purchase GROUP BY


Gender;

2. SELECT City, MIN(Marks) FROM purchase GROUP BY CITY;


3. SELECT Gender, COUNT(*) FROM purchase GROUP BY
Gender;

ANSWER 2
CREATE TABLE cloth (CCODE VARCHAR(30) PRIMARY KEY, CNAME
VARCHAR(255), SIZE VARCHAR(20), COLOR VARCHAR(40), PRICE
INT, DOP DATE);

INSERT INTO cloth VALUES


("C001", "JEANS", "XL", "BLUE", 990, "2022-01-21"),
("C002", "T SHIRT", "M", "RED", 599, "2021-12-12"),
("C003", "TROUSER", "M", "GREY", 399, "2021-11-10"),
("C004", "SAREE", "FREE", "GREEN", 1200, "2019-11-12"),
("C005", "KURTI", "L", "WHITE", 399, "2021-12-07");
1. SELECT LOWER(CNAME) FROM cloth;

2. SELECT MIN(CPRICE) FROM cloth;

3. SELECT COUNT(*) FROM cloth WHERE SIZE="M";


ANSWER 3
CREATE TABLE stock (Pid INT PRIMARY KEY, PName
VARCHAR(255), Category VARCHAR(150), Qty INT, Price INT);

INSERT INTO stock VALUES (1, "Keyboard", "IO", 15, "450"),


(2, "Mouse", "IO", 10, 350),
(3, "Wifi-router", "NW", 5, 2600),
(4, "Switch", "NW", 3, 3000),
(5, "Monitor", "O", 10, 4500),
(6, "Printer", "O", 4, 17000);

ANSWER 4
SELECT * FROM stock ORDER BY Price DESC;
ANSWER 5
SELECT MONTHNAME(DOP) AS "Month Name", 0.3*PRICE AS "30%
OF PRICE" FROM cloth;

ANSWER 6
1. SELECT Class, COUNT(*) FROM purchase GROUP BY Class;

2. SELECT Name FROM purchase WHERE Name LIKE "%ek";


3. UPDATE purchase SET Marks=Marks-10 WHERE Marks IN
(430, 470, 360);
BEFORE

AFTER

ANSWER 7
1. SELECT RIGHT(CCODE, 2) FROM cloth;
2. SELECT ROUND(PRICE/44, 3) FROM cloth;

3. SELECT SUBSTR(COLOR, 3, 2) FROM cloth;

ANSWER 8
CREATE TABLE store (StoreId VARCHAR(10), Name VARCHAR(50),
Location VARCHAR(50), City VARCHAR(50), NoOfEmp INT,
DateOpen DATE, SalesAmt INT);
INSERT INTO store VALUES
('S101', 'Planet Fashion', 'Bandra', 'Mumbai', 7, '2015-10-16',
40000),
('S102', 'Vogue', 'Karol Bagh', 'Delhi', 8, '2015-07-14', 120000),
('S103', 'Trends', 'Powai', 'Mumbai', 10, '2015-06-24', 30000),
('S104', 'Super Fashion', 'Thane', 'Mumbai', 11, '2015-02-06',
45000),
('S105', 'Annabelle', 'South Extn.', 'Delhi', 8, '2015-04-09', 60000),
('S106', 'Rage', 'Defence Colony', 'Delhi', 5, '2015-03-01', 20000);

1. SELECT Name, SalesAmt FROM store WHERE


City="Mumbai";
2. SELECT * FROM store ORDER BY Name;

3. SELECT City, COUNT(*) FROM store GROUP BY City HAVING


COUNT(*) > 2;

You might also like