Professional Documents
Culture Documents
Data Engineer SQL Assignment
Data Engineer SQL Assignment
Part A
You have 2 tables:
Id Cntr
1 100
2 200
3 NULL
4 300
5 null
Table b (Id int PK, Cntr int)
Id Cntr
2 NULL
4 4000
5 5000
7 NULL
8 8000
ON A.ID=B.ID
ON A.ID=B.ID
ON A.ID=B.ID
ON A.ID=B.ID
Part B
Table A structure:
1. Write a query that returns the second max premium of the policies (Expected output PolicyId ,
Premium)
2. Write a query that returns the two most recent dates of each policy (Expected output PolicyId
PremDate)
3. Write a query that returns the diff in days between the PremDate and the previous PremDate of
the same PolicyID (In your answer use the LAG window function) ( Expected output PolicyId,
PremDate, Previous PremDate, Diff )
4. Write a query that returns PolicyID distribution
5. Write a query that returns the number of duplicate PolicyIDs
6. Write a query that returns the unique number of PremDates in the table
7. Write a query that returns the total Premium per day ( according to the PremDate )
Table B structure:
1. Write a query that returns every WorkAreaCity where the average Premium per PolicyId is
greater than 400 ( In your answer use at least one CTE table ) (Expected output WorkAreaCity)
2. Write a query that returns the two most active Agents. Agent activity is based on the number of
Policies ( PolicyId ) that were sold during the last year (Expected output Agentname, Number of
Policies)
Part C
General questions:
1. Given two tables, table A contains 10 records and table B contains 20 records
a. What are the minimum records will be displayed if you will use Inner join?
b. What are the minimum records will be displayed if you will use right join?
2. What is the difference between union and union all?
3. Can you offer a different way to replace the distinct clause in the select statement and still
maintain the same functionality of distinct?
4. If you apply Count (*) on a given table and apply count (distinct<column>) and the <column> is
Primary key, will the results of the queries be different? Explain.