MYSQL QUESTIONS
MYSQL QUESTIONS
Q-4) Consider table given in Q-3, write SQL query to display the
records in decreasing order of price.
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.
ANSWER 1
CREATE TABLE purchase (`Roll No.` INT PRIMARY KEY, Name
VARCHAR(255), Class VARCHAR(30), Gender VARCHAR(20), City
VARCHAR(255), Marks INT);
ANSWER 2
CREATE TABLE cloth (CCODE VARCHAR(30) PRIMARY KEY, CNAME
VARCHAR(255), SIZE VARCHAR(20), COLOR VARCHAR(40), PRICE
INT, DOP DATE);
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;
AFTER
ANSWER 7
1. SELECT RIGHT(CCODE, 2) FROM cloth;
2. SELECT ROUND(PRICE/44, 3) 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);