0% found this document useful (0 votes)
18 views15 pages

SQL Test

Uploaded by

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

SQL Test

Uploaded by

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

Table A: Table B: Table C:

Col1 Col2 Col3


1 2 3
2 3 4
3 5 7
4 8 9

Q1) Col 1 Col 2


select a.col1, b.col2, c.col3
from A inner join b on a.col1 = b.col2
inner join c on a.col1 = c.col3

Type Answer here

Q2) Col 1 Col 2


select a.col1, b.col2, c.col3
from A inner join b on a.col1 = b.col2
left join c on a.col1 = c.col3

Type Answer here


Col 3 Q3) Col 1
select a.col1, b.col2, c.col3
from A left join b on a.col1 = b.col2
left join c on a.col1 = c.col3

Type Answer here

Q4) Col 1
Col 3 select a.col1, b.col2, c.col3
from A left join b on a.col1 = b.col2
inner join c on b.col2 = c.col3

Type Answer here


Col 2 Col 3

Col 2 Col 3
Table Name : Prod_table

Schema and top 10 Rows:


Product ID Date Inventory
ProdA 4/5/2020 10
ProdA 4/6/2020 11
ProdB 4/3/2020 12
ProdB 4/9/2020 14
ProdB 4/13/2020 15
ProdA 5/10/2020 13
ProdB 5/11/2020 14
ProdB 5/12/2020 15
ProdC 6/22/2020 16
ProdC 6/23/2020 17
ProdC 6/22/2020 16
ProdC 6/23/2020 17
….. ….. …...

Month opening inventory is defined by inventory on first available date of the month

1)Write a query to get Month opening inventory of every product


eg ProdA for month Apr will have opening inventory as 10

Sample Output schema : 4 columns

Product Month Year Opening_Inventory


ProdA 4 2020 10
ProdB 4 2020 12
e of the month

2) Write a query to get the inventory for every product on the second last available date of the month

Sample Outpu4 columns

Product Month Year Inventory


ProdA
ProdB
e of the month
Table Name :visit_Table

Visitor ID Visit_Date
VisitorA 4/1/2020
VisitorA 4/2/2020
VisitorB 4/5/2020
VisitorB 4/9/2020
VisitorC 4/10/2020
VisitorC 4/11/2020
….. …..

1)Write a query to get count of visitors those visit on consecutive days


eg VisitorA came on 2 consecutive days
Table Name : SALES_TRANS
DATE ORDER_ID CUSTOMER_ID ITEM_ID QTY TOTAL
12/2/2019 101 1 6 1 ₹ 4.00
12/2/2019 101 1 3 1₹ 17.00
12/10/2019 102 2 2 1 ₹ 1,000.00
12/11/2019 103 3 3 1 ₹ 2.00
12/11/2019 103 3 5 2₹ 34.00
12/11/2019 104 4 1 50 ₹ 75.00
12/19/2019 105 1 1 2₹ 30.00
12/19/2019 105 1 3 5₹ 10.00
12/19/2019 105 1 4 1 ₹ 120.00
12/19/2019 106 3 5 4₹ 68.00
12/19/2019 107 5 4 1 ₹ 120.00

a. Write a query to identify number of newly acquired customers on an eve


b. Write a query to identify the item which was never sold ?
Table Name : ITEM_DIM Table Name : DEPT_DIM
ITEM_ID ITEM_NAME DEPT_NBR UNIT_RETAIL_AMT DEPT_NBR
1 Chocolates 1₹ 15.00 1
2 iPhone 2 ₹ 1,000.00 2
3 Banana 3 ₹ 2.00 3
4 Speaker 2 ₹ 120.00
5 Fresh Vegetab 3₹ 17.00
6 Coke 1 ₹ 4.00
7 Frozen Foods 1 ₹ 8.00

customers on an everyday basis ?


ble Name : DEPT_DIM
DEPARTMENT_NAME
Consumables
Electronics
Fresh Groceries
Input table: visit_table Output:
Visitor ID Visit ID Visit Page Number Page Type
1 1 1 Home Visitor ID
1 1 2 Search 1
1 1 3 Category 2
1 1 4 Product
1 1 5 Product
1 2 1 Home
1 2 2 Product
1 2 3 Product
1 3 1 Home
1 3 2 Product
1 3 3 Product
1 3 4 Category
2 1 1 Home
2 1 2 Product
2 1 3 Product
2 1 4 Category
2 1 5 Product
2 1 6 Category
2 1 7 Product

Write a query to identify the number of pages viewed by visitor during a visi
If more than one category page was visited consider the first page and ignor
Visit ID No of Pages
1 2
1 2

sitor during a visit after a category page,


rst page and ignore category page for calculating the number of pages ?
Input table: visit_table
Visitor ID Visit Page Time Stamp Page Type
1 1 3/20/2021 12:15 Home
1 2 3/20/2021 12:15 Product
1 3 3/20/2021 12:15 Cart
1 4 3/20/2021 12:15 Checkout
1 5 3/20/2021 12:16 Purchase
2 1 3/20/2021 14:21 Home
2 2 3/20/2021 14:21 Search
2 3 3/20/2021 14:21 Cart
2 4 3/20/2021 14:22 Checkout
2 5 3/20/2021 14:22 Home
3 1 3/20/2021 16:21 Home
3 2 3/20/2021 16:21 Category
3 3 3/20/2021 16:21 Cart
3 4 3/20/2021 16:22 Checkout
3 5 3/20/2021 16:22 Purchase
3 6 3/20/2021 16:23 Home
3 7 3/20/2021 16:23 Product
3 8 3/20/2021 16:23 Cart
3 9 3/20/2021 16:23 Checkout
3 10 3/20/2021 16:24 Purchase

Query 1. Find the time taken by a Visitor to complete purchase from cart page
Descriptive 2. What are the observations from the above data? What does the result look like for each v
Output
Visitor ID Cart -> Purchase Time (Seconds)
1 23
2 NULL Since there is no purchase, result would be null
3 82 Two purchases for the visitor, so two rows of result unless aggregated
3 41

e result look like for each visitor?


f result unless aggregated

You might also like