0% found this document useful (0 votes)
5 views2 pages

Questions

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

Questions

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

SQL Assessment

Summary of Data

- The data in table [dbo].[sql_test_delivery] contains transactional data for


different types of fuel deliveries
- Each delivery for an Account (account id & name) and Tank (tank_number) belongs to a
CSC (csc) that rolls under a Region (csc_region) which is under a Business Unit (csc_bu)
- The number of Units delivered in gallons is in column Units_Delivered
- The total capacity of a tank is in column Tank_useable_size
- Fill % = (Units_Delivered / Tank_useable_size) *100
- If Fill% >95, it is an “Out of Gas”,
>=25 % and <= 95%, it is a “Regular Fill”,
<25%, it is an “Inefficient Fill”,
= 0, it is a “Zero Fill”
- Collectively, these 4 classifications above are known as Fill Types
- The combination of Account, Db, and Trx_Unique_key is unique for each delivery/record in this
table.

Please make sure that SQL code are error free and executable. The expectation is that every query
should return data.

1) Design a SQL code that gives a new column which will identify every delivery by its fill type.
(Out of gas, Zero Fill, Inefficient, Regular Fill)

For example, if Fill % = 50, then the new column should have a value as “Regular Fill”

The code should include the calculation of Fill %.

2) Design a SQL code that returns Max, Min & Average Fill % by CSC. Please round the overall
result to 2 decimal places and sort the results by decreasing order of average values.

3) Design a SQL code that returns the Delivery Date, Units Delivered, Tank Useable Size & Fill %
for all “Out of Gas” deliveries belonging to CSC= “1550 Marlboro, NY”

4) This table has duplicate entries. Design a SQL code that returns all duplicate rows all with
their counts.
5) Design a SQL code that will delete all duplicate entries with a single query and no
intermediate table. Please mention counts before the delete query, count of duplicate rows,
and counts after execution of delete query.

6) Design a SQL code that will return all Regions and their Products with total sales > $52,000

7) Design a SQL code that will return the product with 3rd highest margin for every CSC.
Margin can be calculated at a delivery level (product sale amount – product cost)

8) Design a SQL code that will return the CSC with the 5th highest margin

9) In the column “CSC”, the last 2 characters are the initials for the State the CSC belongs.
Write a SQL query that will extract the STATE initials from the field CSC.

For example: 1280 Rome, NY will have NY as the output of above query.

10) With data in the below table, swap all NBC and CBS values (i.e., change all NBC values to CBS
and vice versa) with a single update query and no intermediate temp table.

Table Name: SHOWS_NETWORKS


ID Show Network
1 AAA NBC
2 BBB NBC
3 CCC CBS
4 DDD CBS

You might also like