-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvh_test_solution.txt
191 lines (72 loc) · 4.01 KB
/
pvh_test_solution.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
PVH TEST SOLUTION
=====================================================
PYTHON
# A. If Category contains 'Accessories', then make Business = 'DFG'
df.loc[df.Category == 'Accessories', 'Business'] = 'DFG'
df
# B. If Gender = 'Children' and Division = 'CK', then make Business = 'CK-KIDS'
df.loc[(df.Gender == 'Children') & (df.Division == 'CK'), 'Business'] = 'CK-KIDS'
df
------------------------------------------------------------------------------------------------
# A. Read the dataset into R or Python. Assume its in a file named Cust_Sales.csv
df = pd.read_csv('Cust_Sales.csv')
df.head(5)
# B. Treat NULLs and Blanks in Birth_Date column
df.isnull().sum()
print(df.replace(r'^\s*$', np.nan, regex=True))
df["Birth_Date"] = df["Birth_Date"].replace('#NA', np.nan)
df['Birth_Date'].fillna(method = 'bfill', inplace = True)
df
C. Filter out(ie; Delete) records for X29 Store
df.drop([10009],axis=0,inplace = True)
df
D. Aggregate the data at a Store Category Level.
df.groupby(['Store','Category']).sum()
df
===========================================================================
SQL
-1)-From the below Sales_Emp and Sales_Trans tables can you create a table with ID, Name and Net Sales of all Employees. If an Employee doesn’t as a sales record in Sales_Trans, consider the sales amount to be 0.
SELECT sales_emp.sales_id, sales_emp.sales_name, NVL(SUM(sales_trans.sales_amount),'0') as net_sales
FROM sales_emp
LEFT JOIN sales_trans
ON sales_emp.sales_id = sales_trans.sales_id
GROUP BY sales_emp.sales_id;
--Q2) Categorize the Employees as Star Performer based on their Net Sales. An Employee is given StarPerformer if the Net Sales of that Employee is >35% of Total Sales amount of all empoyees
SELECT sales_emp.sales_id, sales_emp.sales_name, NVL(SUM(sales_trans.sales_amount),'0') > 0.35 * (select sum(sales_amount) from sales_trans) as pct_total_sales
CASE
WHEN (NVL(SUM(sales_trans.sales_amount),'0') > 0.35 *(select sum(sales_amount)from sales_trans)) THEN 'STAR'
ELSE 'NO'
END AS 'Reward'
FROM sales_emp
LEFT JOIN sales_trans
ON sales_emp.sales_id = sales_trans.sales_id
GROUP BY sales_emp.sales_id;
--Q3) From the below Sample table Display a report showing each student’s Marks in individual subjects and the highest Marks scored by any student in those subjects
select stu_id, stu_name, course_id, marks, max(marks) over(partition by course_id order by course_id) as highest
from school;
-4)--In the below Order_Pdt table, write a query to indentify the Orders which were made for both Product IDs 10 and 12.
SELECT DISTINCT orderid FROM order_pdt WHERE pdtid IN(10,12) group by orderid having count(orderid) > 1;
Q5) Refer to Sample table below. It’s a sample of one year of PO data. Explore and analyze the data and tell if the data has sufficient information to solve the problem statement.
Write a SQL code to report Yearly aggregated Order Qty and $ values by Vendor/Product/Division/Shipping Country (as shown in Expected result)
ans--Table has not sufficient information to solve this problem, such as shipment_country 'mexico' does not present in table and we have to convert currency into USD , table does not contain enough data
--Q6) From the below Students table, find out the Students who scored the Max marks in each Course
SELECT course_id, stu_id, stu_name, marks
FROM(
SELECT e.*, ROW_NUMBER() OVER(PARTITION BY course_id order by stu_id desc) as rn
FROM school e
)X
WHERE X.rn = 1;
--Q7) Refer to the Sample table below. Write an SQL code to separate the Orders and Forecasts into columns from rows
select * from (
select channel,
sku,date,f,o
from table
)
pivot
(
LISTAGG(date) within group (order by sku)
for fct_qty in
('fct_qty' as f,
'fct_qty' as o,
)
)