2.4 KiB
MercoParts
Analysis generated on: 4/2/2025 10:03:43 AM
SQL Statement
SELECT AddnlPROC.PartNumber, AddnlPROC.WC2, AddnlPROC.WC3, AddnlPROC.WC4, AddnlPROC.Machine, AddnlPROC.RunStd, MercoPart.LastMonthQty, [Lastmonthqty]*[RunStd] AS MthExtHrs, ([Lastmonthqty]*[RunStd])/22 AS DayExtHrs
FROM MercoPart LEFT JOIN AddnlPROC ON MercoPart.PN = AddnlPROC.PartNumber;
Dependencies
Parameters
- None
What it does
SQL Query Description
Overview
This SQL query retrieves data from two tables: MercoPart
and AddnlPROC
. It joins the two tables based on a common column, PartNumber
, and calculates additional statistics.
Table Overview
- MercoPart: This table contains information about parts managed by Merco.
- Columns:
PN
: Part Number (primary key)LastMonthQty
: Quantity of the part in stock for the last month
- Columns:
- AddnlPROC: This table contains additional process data related to parts.
- Columns:
PartNumber
(foreign key referencingMercoPart.PN
)WC2
,WC3
,WC4
: Additional processing valuesMachine
: Machine used for the part's productionRunStd
: Standard run time for the part
- Columns:
Query Details
The query performs a left join on the two tables based on the PartNumber
column. The results include the following calculations:
- MthExtHrs: Extented hours worked in the last month, calculated as
LastMonthQty * RunStd
- DayExtHrs: Extented hours worked per day, calculated as
(LastMonthQty * RunStd) / 22
SELECT Statement
The query selects the following columns:
PartNumber
from both tablesWC2
,WC3
, andWC4
fromAddnlPROC
Machine
fromAddnlPROC
RunStd
fromAddnlPROC
- Calculated columns:
MthExtHrs
andDayExtHrs
JOIN Clause
The query uses a left join to combine data from both tables. The left join ensures that all records from the MercoPart
table are included in the results, even if there is no matching record in the AddnlPROC
table.
FROM MercoPart
LEFT JOIN AddnlPROC ON MercoPart.PN = AddnlPROC.PartNumber;
Resultset
The query returns a result set with the specified columns and calculated values. The resultset includes data from both tables, but may contain null values for AddnlPROC
columns if there is no matching record in MercoPart
.