21SJCCC025

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Qn-0 Display the database and tables of super_market

Query:
show databases;
use super_market;
show tables;
select * from super_market.branches limit 8;
select * from super_market.transactions limit 8;
Solution:

Qn- 1 Get the details of transaction of ID 100


select * from super_market.transactions where Transaction_ID=100;

Qn-2 get the details of transaction of ID 4408


Qn-3 get all the transaction details with price is greater than 998
select * from super_market.transactions where Price>998;
Qn-4 get the total number of transactions with price greater than 998
select count(*) from super_market.transactions where Price>998;

Qn-5 get the total number of transactions with price range of 900 and 1000
Hint: use between
select count(*) from super_market.transactions where Price between 900 and 1000;

Qn-6 get the transaction details for the price 999 and branch id 66
select * from super_market.transactions where Price =999 and Branch_ID =66;

Qn-7 identify the branch name, location, address and manager name of the above result
select * from super_market.branches where Branch_ID=66;

Qn-8 get the transaction details of the purchases happened on 02 nd May 2022
select * from super_market.transactions where Purchase_Date = '2022-05-02';
Qn-9 get the total number of transactions happened between 01 st Jan 2020 and 31st Jan 2020
select count(*) from super_market.transactions where Purchase_Date between '2020-01-01' and
'2022-01-31';

Qn-10 Fetch the records of purchases happened on 14 th Feb 2020


Answer : none

Summarizing and grouping the records

Qn-1 get the count of transactions per customer


select Customer_ID, count(*) from super_market.transactions group by Customer_ID;

Qn-2 get the total count of transactions of transactions table


Query-select count(*) from transactions

Solution-

3. Identify the top 10 customers based on total sales


Step 1 creating sum(price) column
Select Customer_ID, sum(price) as Total_Price from super_market.transactions group by
Customer_ID order by Total_Price Desc limit 10

Solution-
4. Identify best 5 branches of the supermarket based upon the total price
Select Branch_ID, sum(price) as Total_Price from super_market.transactions group by Branch_ID
order by Total_Price Desc limit 5

5.Identify the best 5 branches of the supermarket based upon the total no. of transactions.
Select Branch_ID, count(*) as 'Total_number_of_transactions' from super_market.transactions
group by Branch_ID order by Total_number_of_transactions Desc limit 5;

You might also like