0% found this document useful (0 votes)
13 views4 pages

MySQL MID Solve by Pallab Kumar Nakti

The document outlines the creation of a MySQL database named 'Organization' with a table 'ProductSales' containing sales data for various products sold by employees. It includes SQL queries to retrieve unique products, count sales per product, calculate total sales by employee, find average sales, and list products with total sales exceeding Tk. 100000. The document serves as a guide for performing these operations in SQL.

Uploaded by

debojitdutta187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

MySQL MID Solve by Pallab Kumar Nakti

The document outlines the creation of a MySQL database named 'Organization' with a table 'ProductSales' containing sales data for various products sold by employees. It includes SQL queries to retrieve unique products, count sales per product, calculate total sales by employee, find average sales, and list products with total sales exceeding Tk. 100000. The document serves as a guide for performing these operations in SQL.

Uploaded by

debojitdutta187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

MySQL Mid question (Raihan Sobhan) Solve:


Create a database named ‘Organization’ and in that database, create the following table named

‘Information’:

Serial Name Product Sales


1 John Laptop 120000
2 Bob Phone 40000
3 Mark PC 80000
4 Alice Camera 75000
5 Ross Phone 60000
6 John Laptop 200000
7 Mark Camera 110000
8 Bob Laptop 150000

Required:

i) Write a query that returns all unique products sold.

ii) Write a query that counts the number of sales for each product.

iii) Write a query to calculate the total sales made by each employee. Sort the results in descending

order of total sales.

iv) Write a query to find the average sale amount across all sales.

v) Write a query that lists all products that have total sales amounts greater than Tk. 100000.

1. Create table with the data:

Made by Pallab Kumar Nakti A&IS (29th)


2

CREATE TABLE ProductSales (

Serial INT,

Name VARCHAR(50),

Product VARCHAR(50),

Sales INT

);

INSERT INTO ProductSales (Serial, Name, Product, Sales) VALUES

(1, 'John', 'Laptop', 120000),

(2, 'Bob', 'Phone', 40000),

(3, 'Mark', 'PC', 80000),

(4, 'Alice', 'Camera', 75000),

(5, 'Ross', 'Phone', 60000),

(6, 'John', 'Laptop', 200000),

(7, 'Mark', 'Camera', 110000),

(8, 'Bob', 'Laptop', 150000);

2. Solving the Questions:

Made by Pallab Kumar Nakti A&IS (29th)


3

select * from ProductSales;

-- Required:

-- i) Write a query that returns all unique products sold.

select distinct product from productsales;

-- ii) Write a query that counts the number of sales for each

--product.

select product, sum(sales) from productsales group by product;

-- iii) Write a query to calculate the total sales made by -

--each employee. Sort the results in descending order of total

--sales.

select name, sum(sales) from productsales group by name;

-- iv) Write a query to find the average sale amount across all

--sales.

select avg(sales) from productsales;

-- v) Write a query that lists all products that have total -

--sales amounts greater than Tk. 100000.

Made by Pallab Kumar Nakti A&IS (29th)


4

select product, sum(sales) as Total from productsales group

by product having total>100000;

END

Made by Pallab Kumar Nakti A&IS (29th)

You might also like