# Scott'sQ1 Analysis generated on: 4/2/2025 10:10:43 AM --- ## SQL Statement ```sql SELECT DISTINCTROW Machines.PartNumber AS PartNumber, First(Machines.MachineName) AS MachineName, First(Machines.CycleTime) AS CycleTime, First(Machines.Prime) AS Prime, First(UCase$(Left$([CutType],4))) AS Expr1 FROM Machines INNER JOIN Process ON Machines.PartNumber = Process.PartNumber GROUP BY Machines.PartNumber HAVING (((First(Machines.MachineName))="C-6000" Or (First(Machines.MachineName))="C-8000" Or (First(Machines.MachineName))="C-9000") AND ((First(UCase$(Left$([CutType],4))))="MULT")) ORDER BY Machines.PartNumber, First(Machines.MachineName); ``` ## Dependencies - [[Tables/Machines]] - [[Tables/Process]] ## Parameters - *None* ## What it does **SQL Query Description** ===================================== This SQL query retrieves specific information from two tables: `Machines` and `Process`. The query filters the data based on certain conditions and returns a distinct list of rows that meet these criteria. **Query Breakdown** -------------------- ### 1. Table Joins The query joins the `Machines` table with the `Process` table on the `PartNumber` column. This allows for the retrieval of additional information from the `Process` table that is related to each machine in the `Machines` table. ### 2. Column Selection and Aggregation The query selects the following columns: * `PartNumber`: The unique part number of each machine. * `MachineName`: The first occurrence of the machine name, which will be either "C-6000", "C-8000", or "C-9000". * `CycleTime`: The first occurrence of the cycle time. * `Prime`: The first occurrence of the prime value. * `Expr1`: A modified version of the cut type (more on this below). ### 3. Grouping and Having Clause The query groups the data by the `PartNumber` column. However, instead of grouping all machines together, the query uses the `HAVING` clause to filter out rows that do not meet certain conditions. The conditions in the `HAVING` clause are: * The machine name is either "C-6000", "C-8000", or "C-9000". * The modified cut type (see below) is "MULT". ### 4. Modified Cut Type The query uses a combination of string functions to create a modified version of the `CutType` column, which is stored in the `Process` table. The function used is: ```sql UCase$(Left$([CutType],4)) ``` This function takes the first 4 characters of the `CutType` column (ignoring any leading or trailing whitespace), converts them to uppercase using the `UCase()` function, and returns the result as a string. ### 5. Ordering The query orders the results by the `PartNumber` column and then by the first occurrence of the machine name. This ensures that machines with unique names are listed before those with duplicate names. **Example Use Case** -------------------- This query might be used in a manufacturing environment to retrieve information about specific machines, such as their part numbers, cycle times, and prime values. The query could also be used to identify which machines meet certain criteria, such as having a specific machine name or cut type.