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

SQL Assignment

Uploaded by

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

SQL Assignment

Uploaded by

guptaaman5284
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL – Assignment

1. We have a table which has 5 columns.


a. User_id, poll_id, poll_option_id, amount, created_dt
b. Users invest money on these different poll options - these entries are there in the table
c. One of the options is the outcome of the event.
Event: How many matches will the Indian cricket team win in 2022?
i. Less than 50
ii. 50-60
iii. 61-65
iv. Greater than 65
 India wins 63 matches in the end.
 Option C is the winner
 Money invested in option A, B and D should be proportionately distributed
amongst users who invested money in option C
 For example - If total money invested in option A, B and D is Rs. 1500 and there
are 3 users who invested 500 in option C {250, 200 and 50}
 These users would receive (750, 600 and 150 respectively) - sum is 1500.

d. Write down a query for the above settlement process

Input Table:

User_ID Poll_Id Poll_Option_Id Amount Created_dt


id1 p1 A 200 2021-12-01
id2 p1 C 250 2021-12-01
id3 p1 A 200 2021-12-01
id4 p1 B 500 2021-12-01
id5 p1 C 50 2021-12-01
id6 p1 D 500 2021-12-01
id7 p1 C 200 2021-12-01
id8 p1 A 100 2021-12-01

Output Table: Option C wins

User ID Returns
id2 1000
id5 200
id7 800
2. Below table (Table 1) has city and month wise sales data. Create a SQL query to return
output as illustrated in Table 2.
Table 1

City Year Month Sales

Delhi 2020 5 4300


Delhi 2020 6 2000
Delhi 2020 7 2100
Delhi 2020 8 2200
Delhi 2020 9 1900
Delhi 2020 10 200
Mumbai 2020 5 4400
Mumbai 2020 6 2800
Mumbai 2020 7 6000
Mumbai 2020 8 9300
Mumbai 2020 9 4200
Mumbai 2020 10 9700
Bangalore 2020 5 1000
Bangalore 2020 6 2300
Bangalore 2020 7 6800
Bangalore 2020 8 7000
Bangalore 2020 9 2300
Bangalore 2020 10 8400

Table 2
Previous Next Month
City Year Month Sales YTD Sales
Month Sales Sales
Delhi 2020 5 4300 2000 4300
Delhi 2020 6 2000 4300 2100 6300
Delhi 2020 7 2100 2000 2200 8400
Delhi 2020 8 2200 2100 1900 10600
Delhi 2020 9 1900 2200 200 12500
Delhi 2020 10 200 1900 12700
Mumbai 2020 5 4400
Mumbai 2020 6 2800
Mumbai 2020 7 6000
Mumbai 2020 8 9300
Mumbai 2020 9 4200
Mumbai 2020 10 9700
Bangalore 2020 5 1000
Bangalore 2020 6 2300
Bangalore 2020 7 6800
Bangalore 2020 8 7000
Bangalore 2020 9 2300
Bangalore 2020 10 8400

Submit the two SQL queries as two separate files with names: <Your full
name>_SQL_ans1 and <Your full name>_SQL_ans2

You might also like