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

SQL Codes

The document outlines various MySQL database tasks involving employee data, customer orders, course fees, social media activity, and employee salaries. Each section specifies the database name, table structures, and SQL query requirements for retrieving specific information. Additionally, it includes execution time limits and notes on ensuring the correct database is used in queries.

Uploaded by

Darshan Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Codes

The document outlines various MySQL database tasks involving employee data, customer orders, course fees, social media activity, and employee salaries. Each section specifies the database name, table structures, and SQL query requirements for retrieving specific information. Additionally, it includes execution time limits and notes on ensuring the correct database is used in queries.

Uploaded by

Darshan Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

My-SQL: Employee Data

Environment Specifications & Instructions:


 Type of Database: MySQL
 Database Name to be used: EmployeeData

Existing Information:

 Table Descriptions:

tblemployee Table is described below:

Column Name Data Type CONSTRAINT Extra

EMPID Int (11) - -


EMPNAME varchar(50) - -
SALARY Int (11) - -
MANAGERID Int (11) - -
DEPARTMENT varchar(10) - -

tblemployer Table is described below:

Column Name Data Type CONSTRAINT Extra

EMPID Int (11) - -


EMPNAME varchar(50) - -
SALARY Int (11) - -
MANAGERID Int (11) - -
DEPARTMENT varchar(10) - -

Problem Statement:

Write a standard SQL query that will return the value of "EMPID" and "EMPNAME" for those
employees who earn more than their managers. Additionally, the query will return the salary of an
employee as column name "EMPSALARY" and the salary of a manager as column name
"MANAGERSALARY"

The rows should be returned in the increasing order of "EMPID"

Column Name: EMPID, EMPNAME, EMPSALARY, MANAGERSALARY

Sample Output:

Note:
1.) Make sure to USE EmployeeData in the query before submitting as your output is compared
with the expected result.
2.) You can run multiple queries at once and see their output in the output section in the order where
the queries were written.

Execution time limit:


100 Seconds

MY_SQL QUERY:
My-SQL: Order placed by Customer
Environment Specifications & Instructions:
 Type of Database: MySQL
 Database Name to be used: Customerdb

Existing Information:
 Table Descriptions:

orders Table is described below:

Column Name Data Type CONSTRAINT Extra


order_id Int (11) Primary key -
customer_id Int (11) - -
Order_date date - -
total_amount Decimal(10,2) - -

Problem Statement:

Write a SQL query to find the customer who has placed more than two orders with a total amount
excedding $500. Display the customer_id and the total number of orders placed by that customer as
total_orders.

The rows should be returned in the increasing order of “customer_id” .

Column Name: customer_id, total_orders

Sample Output:
Note:
1.) Make sure to use Customerdb in the query before submitting as your output is compared with
the expected result.
2.) You can run multiple queries at once and see their output in the output section in the order where
the queries were written.

Execution time limit:


100 Seconds

MY_SQL QUERY:
My-SQL: Course Fees
Environment Specifications & Instructions:
 Type of Database: MySQL
 Database Name to be used: DB_Institute

Existing Information:
 Table Descriptions:

TBL_Students_Enroll is described below:

ID Int
StudentNm varchar(50)
StudentID varchar(50)
EmailID varchar(50)
CourseNm varchar(50)
MobileNo varchar(50)
Address varchar(50)
DtEnroll datetime

TBL_Students_Fees is described below:

Column Name Data Type


ID Int
Studentid varchar(50)
FeesPaid Int
FeesDue Int
PaymentDate datetime

Problem Statement:
Construct a query that displays StudentID, Name, DateOfFnrollment, FeesPaid, FeesDue and
PaymentDate of students who have not paid fees for the Python course.

The result should be in the order of the student's Name.

Column Name: StudentID, Name, DateOfEnrollment, FeesPaid, FeesDue, PaymentDate

Sample Output:
Note:
1.) Make sure to USE DB_Institute in the query before submitting as your output is compared with
the expected result.
2.) You can run multiple queries at once and see their output in the output section in the order where
the queries were written.

Execution time limit:


100 Seconds

MY_SQL QUERY:
My-SQL : Most Active Users on Social Media
Environment Specifications & Instructions:
 Type of Database: MySQL
 Database Name to be used: SocialData

Problem Statement:

Write a SQL query to find the top 4 most active users on a social media platform, where
activity is defined as the maximum number of posts created.

oThe query should include a column called the user id as he userld, the username as userName
and no_of_post as topPost that indicates the user who created the maximum number of posts

Return the outout result based on topPost in descending order.

Column Name: userld, userName topPost

Table Descriptions:

 Users is described below:

Column Name Data Type CONSTRAINT Extra

user_id Int (11) Primary Key Auto_increment

username varchar(255) Not NULL -

 Posts is described below:

Column Name Data Type CONSTRAINT Extra

Post_id Int(11) Not NULL Auto_increment

user_id Int(11) Foreign Key -

No_of_posts Int(11) Not NULL -


Sample Output:

Note:
1.) Make sure to USE SocialData in the query before submitting as your output is compared with
the expected result.
2.) You can run multiple queries at once and see their output in the output section in the order where
the queries were written.

Execution time limit:


100 Seconds

MY_SQL QUERY:
My-SQL: Employee with Highest Salary
Environment Specifications & Instructions:
 Type of Database: MySQL
 Database Name to be used: CompanDb

Existing Information:
 Table Descriptions:

departments Table is described below:

Column Name Data Type CONSTRAINT Extra


department_id Int (11) Primary Key -
department_name varchar(50) Not NULL -

employees Table is described below:

Column Name Data Type CONSTRAINT Extra


employee_id Int (11) Primary key -
first_name varchar(50) - -
last_name varchar(50) - -
department_id Int (11) - -
hire_date Datetime - -

salaries Table is described below:

Column Name Data Type CONSTRAINT Extra


salary_id Int (11) Primary key -
Employee_id Int (11) - -
salary Decimal (10,2) - -
Effective_date date - -

Problem Statement:

Write a SQL query to retrieve a list of department _id, department_name and the first_name & the
last_name of the employee with their salary in is each department. If a department has no employees or
salary information, It should still appear in the result with NULL values.

The rows should be returned in the increasing order of "department id".


Column Name: department_id, department_name, first_name, last_name, salary

Sample Output:

Note:
1.) Make sure to USE CompanyDb in the query before submitting as your output is compared with
the expected result.
2.) You can run multiple queries at once and see their output in the output section in the order where
the queries were written.

Execution time limit:


100 Seconds

MY_SQL QUERY:

You might also like