Get power lines to maintain
In the provided GridStructure table, the fields that describe the connection between lines (EquipmentID,EquipmentID_To,EquipmentID_From) and the characteristics of the lines (e.g. Description, ConditionAssessment, VoltageLevel) are already defined.
Now, your task is to find the connected lines of the line with EquipmentID = 3 that have bad or repair as ConditionAssessment and have a VoltageLevel equal to HV. By doing this, you can answer the following question:
Which lines have to be replaced or repaired according to their description and their current condition?
You have to create a CTE to find the connected lines and finally, to filter on the desired characteristics.
Diese Übung ist Teil des Kurses
Hierarchical and Recursive Queries in SQL Server
Anleitung zur Übung
- Define the CTE
maintenance_List. - Start the evaluation for line 3.
- Join
GridStructurewithmaintenance_Liston the corresponding endpoints. - Use
LIKEto filter the power lines withConditionAssessmentof eitherexchangeorrepair, and aVoltageLevelofHV.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
-- Define the table CTE
___ ___ (Line, Destination, Source, Description, ConditionAssessment, VoltageLevel) ___ (
SELECT
EquipmentID,
EquipmentID_To,
EquipmentID_From,
Description,
ConditionAssessment,
VoltageLevel
FROM GridStructure
-- Start the evaluation for line 3
___ EquipmentID = ___
UNION ALL
SELECT
Child.EquipmentID,
Child.EquipmentID_To,
Child.EquipmentID_FROM,
Child.Description,
Child.ConditionAssessment,
Child.VoltageLevel
FROM GridStructure Child
-- Join GridStructure with CTE on the corresponding endpoints
___ maintenance_List
ON maintenance_List.Line = Child.___)
SELECT Line, Description, ConditionAssessment
FROM maintenance_List
-- Filter the lines based on ConditionAssessment and VoltageLevel
WHERE
(ConditionAssessment ___ '%exchange%' ___ ConditionAssessment ___ '%repair%') ___
VoltageLevel LIKE '%HV%'