I. BACKGROUND
Resc table preserves the system's first-level, two-level functional modules, while preserving the function of the two-level function module pages, the PID defines the parent-child relationship.
Want to through the Resc table, sorting out a, level, level two function module correspondence, similar to this result.
Second, the realization method
Select Case when pid=1 then ' user Management ' when pid=4 then ' Agent Management ' when pid=8 then ' media Management ' when pid=21 then ' report Management ' when pid=26 then ' content tube Pid=30 then ' performance Management ' when pid=34 then ' financial Management ' END as menu, ' name ', PID from Rescwhere pid in (select id from Resc where pi d=0) ORDER by PID
Execution Result:
The results are pasted into Excel, and the merged cells are combined to get the expected results, which can be tracked in Excel.
Third, the theory
case expressions in SQL, you can implement If-then-else logic.
There are two types of case expressions:
Simple case expression, using an expression to determine the return value;
Searches the case expression, using conditions to determine the return value.
Using simple case expressions
Case Search_expression
When Expression1 then RESULT1
When Expression2 then RESULT2
...
When Expressionn then RESULTN
else Default_result
End
Keyword Description:
Search_expression, the expression to be evaluated, a field of the data table;
Expressionx, is the expression that compares with the search_expression;
RESULT1, which is the value returned when the expression is met
Default_result, which is the default return value when an expression cannot be matched.
2. Search for Case expressions
Case
When Condition1 then RESULT1
When Condition2 then RESULT2
...
When Conditionn then RESULTN
else Default_result
End
Keyword Description:
Condition, is the expression to be evaluated;
result, which is the return value, Condition1 is true, returns RESULT1, and so on.
Default_result, which is the default return value when an expression cannot be matched.
MySQL CASE expression