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

Internshala

The document describes a task to write an SQL query using data from tables in a ResearchInstitute database. The tables contain information about researchers, mentors, papers, and the relationships between them. The query should return subject names that contain the letter "b" and have papers written under the guidance of more female mentors than male mentors. Sample data is provided for the researchers table.

Uploaded by

Bhavesh
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)
51 views

Internshala

The document describes a task to write an SQL query using data from tables in a ResearchInstitute database. The tables contain information about researchers, mentors, papers, and the relationships between them. The query should return subject names that contain the letter "b" and have papers written under the guidance of more female mentors than male mentors. Sample data is provided for the researchers table.

Uploaded by

Bhavesh
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/ 11

Question 1 - Non-local orders

You are given 3 tables salesman, customer, and orders.

Task

Write an SQL query to get the following result:

● Find all the non-local orders by looking at the salesmen that generated orders for their
customers but are located elsewhere unlike their customers, and fetch the details like
order_no, name of the customer, customer_id, salesman_id.

Arrange the final output in the increasing order of the order_no.

Table description

Input format

Table: salesman

Field Type Description

id Integer Represents the unique id of the salesman

name String Represents the name of the salesman

city String Represents the city of the salesman

commission Integer Represents the commission of the salesman

Table: customer

Field Type Description

id Integer Represents the unique id of the customer

name String Represents the name of the customer

city String Represents the city of the city

grade Integer Represents the score of the customer for his


consistency in orders
salesman_i Integer Represents the unique id of the salesman
d

Table: orders

Field Type Description

order_no Integer Represents the id of the order

purchase_amount Integer Represents the amount spent on the order

order_date Date Represents the date of order

customer_id Integer Represents the unique id of the customer

salesman_id Integer Represents the unique id of the salesman

Output format

Field Type Description

order_no Integer Represents the id of the order

customer_name String Represents the name of the customer

customer_id Integer Represents the unique id of the customer

salesman_id Integer Represents the unique id of the salesman

Example Sample Input

Table: salesman

id name City Commission

101 James NewYork 150

102 Nail Paris 130

103 Alex London 110

104 Mcoy Paris 140

105 Paul Rome 130


106 Lauson SanJose 120

Table: customer

id name City grade salesman_id

1 Nick NewYork 100 101

2 Brad NewYork 200 102

3 Graham California 200 103

4 Julie London 300 104

5 Fabian Paris 300 105

6 Geoff Berlin 300 106

7 Jos Moscow 100 101

8 Guzan London 200 102

Table: orders

order_no purchase_amount order_date customer_id salesman_id

7001 250 2012-10-05 5 105

7009 270 2012-12-10 1 101

7002 60 2012-10-05 5 105

7004 110 2012-08-17 2 102

7007 950 2012-09-10 3 103

7005 2450 2012-07-27 8 102

7008 5700 2012-09-10 4 104

7003 1980 2012-10-10 7 101

7006 75 2012-10-10 6 106

7010 3045 2012-06-27 1 101


Sample output table

order_no customer_name customer_id salesman_id

7001 Fabian 5 105

7002 Fabian 5 105

7003 Jos 7 101

7004 Brad 2 102

7005 Guzan 8 102

7006 Geoff 6 106

7007 Graham 3 103

7008 Julie 4 104

Question 2 - Employee Incentive Calculation

A food store is planning to give incentive to it's employees based on their monthly performance
in sales.

Incentive is different for each position and each position have it's max limit for incentive.

Sales target to avail the incentive is a milestone.

Employee makes incentive everytime he completes a milestone of sales.

Milestone is different for each position.

You are given the data for a month in the database store_data.

Task:

Find amount of incentive made by each employee.


Table Description

Input Format:

Table: employee

Name Type Description

employee_id int Represents the unique id of employee

name string Represents the name of employee

pos_id string Represents the id of position of employee

emp_sale int Represents the sale of employee

Table: incentive_details

Name Typ Description


e

p_id int Represents the unique id of position

position_nam strin Represents the name of position


e g

sales_milesto int Represents the sales target to achieve a milestone


ne

incentive int Represents the amount of incentive made on completing single target

cap int Represents the maximum incentive of a position

Output Format:

Name Typ Description


e

employee_id int Represents the id of employee

incentive_ma int Represents the incentive made by the employee


de

Sample Input:

Table: employee

employee_id name pos_id emp_sale

201 Jackson P61 456

202 Nick P62 267

203 Joffrey P62 324

204 Misty P63 154

205 Jack P61 532

Table: incentive_details

p_id position_name sales_milestone incentive cap

P61 GM 120 15000 50000

P62 AM 85 8000 23500

P63 Staff 45 5000 13000

Sample Output:

employee_id incentive_made

201 45000

202 23500

203 23500

204 13000
205 50000

Question 3 - Research papers in institute


There are research institutes with Researchers who have written papers under the guidance of
their mentors. You are given a database named ResearchInstitute for one such Institution.

Table description

The database ResearchInstitute consists of the following tables:

Table name Description

researchers A table that contains the list of all researchers at the institute

mentors A table that contains the list of all mentors at the institute

papers A table that contains the list of all papers written by


researchers

research_paper A table that contains a list of papers and their respective


researchers

research_mentor A table that contains a list of researchers and mentors they


are taking guidance from

Table: researchers

● r_id represents the researcher ID


● r_name represents the name of the researcher
● r_gender represents the gender of the researcher (male or female)

Table: mentors

● m_id represents the mentor ID


● m_name represents the name of the mentor
● m_gender represents the gender of the mentor (male or female)
Table: papers

● ​p_id represents the paper ID


● p_subject represents the name of the subject

Table: research_paper

● r_id represents the researcher ID


● ​p_id represents the paper ID

Table: research_mentor

● r_id represents the researcher ID


● ​m_id represents the mentor ID

Entity Relationship Diagram

Task

Write an SQL Query to find subjects that contain the alphabet "b" and have papers written under
the guidance of more female mentors than male mentors.

Sample Input

Table: researchers

r_id r_name r_gender

R001 Mary F

R002 Alice F

R003 Bob M

R004 Ben M
R005 Mike M

R006 Tara F

R007 Anita F

R008 Lisa F

R009 Missy F

R010 John M

Table: mentors

m_id m_name m_gender

M001 Rob M

M002 Jessica F

M003 Rachel F

M004 Joey M

M005 Monica F

Table: papers

p_id p_subject

P001 Microbiology

P002 Theoretical Physics

P003 Theoretical Physics

P004 Microbiology

P005 Microbiology

Table: research_paper

r_id p_id
R001 P001

R002 P002

R003 P003

R004 P004

R005 P005

R006 P001

R007 P002

R008 P003

R009 P004

R010 P005

Table: research_mentor

r_id m_id

R001 M005

R002 M004

R003 M003

R004 M002

R005 M001

R006 M005

R007 M004

R008 M003

R009 M002

R010 M001

Sample output:
p_subject

Microbiology

You might also like