Skip to content

Manufacturing processes for any product is like putting together a puzzle. Products are pieced together step by step, and keeping a close eye on the process is important.

For this project, you're supporting a team that wants to improve how they monitor and control a manufacturing process. The goal is to implement a more methodical approach known as statistical process control (SPC). SPC is an established strategy that uses data to determine whether the process works well. Processes are only adjusted if measurements fall outside of an acceptable range.

This acceptable range is defined by an upper control limit (UCL) and a lower control limit (LCL), the formulas for which are:

The UCL defines the highest acceptable height for the parts, while the LCL defines the lowest acceptable height for the parts. Ideally, parts should fall between the two limits.

Using SQL window functions and nested queries, you'll analyze historical manufacturing data to define this acceptable range and identify any points in the process that fall outside of the range and therefore require adjustments. This will ensure a smooth running manufacturing process consistently making high-quality products.

The data

The data is available in the manufacturing_parts table which has the following fields:

  • item_no: the item number
  • length: the length of the item made
  • width: the width of the item made
  • height: the height of the item made
  • operator: the operating machine
Spinner
DataFrameas
alerts
variable
-- Write your query here
WITH CTE AS (select 
	operator, 
	row_number() over w2 as row_number,
	height,
	avg(height) over w as avg_height,
	stddev(height) over w as stddev_height,
	avg(height) over w + 3*stddev(height) over w/sqrt(5) AS UCL,
	avg(height) over w - 3*stddev(height) over w/sqrt(5) AS LCL	
from manufacturing_parts
window 
 	w as (partition by operator rows between 4 preceding and current row),
	w2 AS (partition by operator)			
	)

SELECT *,
	CASE WHEN height between lcl and ucl then False
	else True end as alert
from cte 
where row_number > 4 
;