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

SQL Test Answers

Web Browers SQL Test
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

SQL Test Answers

Web Browers SQL Test
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Employee

FirstName LastName ID HireDate TerminationDate Salary


Bob Smith 1 2009-06-20 2016-01-01 10000
Joe Jarrod 2 2010-02-12 NULL 20000
Nancy Soley 3 2012-03-14 NULL 30000
Keith Widjaja 4 2013-09-10 2014-01-01 20000
Kelly Smalls 5 2013-09-10 NULL 20000
Frank Nguyen 6 2015-04-10 2015-05-01 60000

1) Write a query to return all employees still working for the company with last names starting with "Smith" sorted by last name then first n

2) Given the `Employee` and `AnnualReviews` tables, write a query to return all employees who have never had a review sorte
3) Write a query to calculate the difference (in days) between the most and least tenured employee still working for the compa
4) Given the employee table above, write a query to calculate the longest period (in days) that the company has gone without a
5) Write a query that returns each employee and for each row/employee include the greatest number of employees that worked
AnnualReviews
ID EmpID ReviewDate
10 1 2016-01-01
20 2 2016-04-12
30 10 2015-02-13
40 22 2010-10-12
50 11 2009-01-01
60 12 2009-03-03
70 13 2008-12-01
80 1 2003-04-12
g with "Smith" sorted by last name then first name. 90 1 2014-04-30

loyees who have never had a review sorted by HireDate.


red employee still working for the company
ays) that the company has gone without a hiring or firing anyone
reatest number of employees that worked for the company at any time during their tenure and the first date that maximum was reached. Ext
first date that maximum was reached. Extra points for not using cursors
Employee
e.Salary
SUM(Change)
Employee
UNION ALL OVER (ORDER BY EventDate ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS ConcurrentEmployees
FROM
FROM
WHERE
SELECT
Employee e
LastName
LEFT JOIN LIKE 'Smith%'
Events
TerminationDate AS date_
AND
) FROM TerminationDate
AnnualReviews r IS NULL
ORDER
ON BY
Employee
1)LastName,
WHERE
SELECT
e.ID = r.EmpID
FirstName;
TerminationDate
WHERE IS NOT NULL
e.ID AS EmployeeID,
SELECT
UNION
r.EmpID ALL
IS NULL
e.FirstName,
2)DATEDIFF(MAX(HireDate),MIN(HireDate))
SELECT CURRENT_DATE() AS date_)
ORDER
AS BY
e.LastName,
tenure_diff_days
SELECT
e.HireDate;
FROMcc.ConcurrentEmployees AS MaxCocurrentEmployees,
MAX(gapDays) AS max_gapDays
cc.EventDate
Employee
FROM ( AS firstMaxDate
3)
WHERE
FROM Employee e
SELECT
TerminationDate
JOINDATE_DIFF(date_,NULL
IS LAG(date_) OVER
CumulativeConcurrentEmployees
(ORDER BY date_), DAY) AS gapDays cc
4)FROM
ON
dateRanges
cc.EventDate) BETWEEN e.HireDate AND COALESCE(e.TerminationDate, CURRENT_DATE())
QUALIFY
5) ROW_NUMBER() OVER (PARTITION BY e.ID ORDER BY cc.ConcurrentEmployees DESC, cc.EventDate) = 1
ConcurrentEmployees
1) DAU
date_ user_count
2019-02-25 9857
2019-02-26 9862
2019-02-27 9870
2019-02-28 9871
2019-03-01 9844
2019-03-02 9834
2019-03-03 9820

DAU 9851

2) Facebook DAU
date_ user_count
2019-02-25 2609
2019-02-26 2540
2019-02-27 2607
2019-02-28 2408
2019-03-01 2613
2019-03-02 2685
2019-03-03 2700

DAU 2595

3) Distribution by hours
hour_ traffic_count traffic_percentage
4 260 0.37%
5 437 0.62%
6 644 0.92%
7 1642 2.35%
8 3206 4.58%
9 4095 5.85%
10 4313 6.16%
11 4038 5.77%
12 3757 5.37%
13 3728 5.33%
14 4446 6.35%
15 4613 6.59%
16 4183 5.98%
17 3565 5.09%
18 3618 5.17%
19 4349 6.21%
20 5514 7.88%
21 5128 7.33%
22 3775 5.39%
23 2207 3.15%

4) Top 10 domains by traffic


domain visits
www.facebook.com 17403
www.youtube.com 13648
coccoc.com 6177
www.google.com 3657
mail.google.com 2250
www.google.com.vn 1516
translate.google.com 1074
accounts.google.com 776
translate.google.com.vn773
www.24h.com.vn 702

You might also like