SQL Codes
SQL Codes
Existing Information:
Table Descriptions:
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"
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.
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:
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.
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.
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:
ID Int
StudentNm varchar(50)
StudentID varchar(50)
EmailID varchar(50)
CourseNm varchar(50)
MobileNo varchar(50)
Address varchar(50)
DtEnroll 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.
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.
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
Table Descriptions:
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.
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:
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.
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.
MY_SQL QUERY: