emp と emp_attributes の 2 つのテーブルがあり、その中で条件付き結合を行いたい
従業員
empno | ename | location | salary
1 | Josh | LA | 1200
2 | Joe | NY | 1000
3 | George | LA | 1500
emp_attributes
empno | attr_name | attr_value
1 | appraised | 10%
1 | basicSalary| 700
2 | basicSalary| 600
2 | appraised | 12%
2 | spouseName | Amelia
3 | appraised | 25%
3 | basicSalary| 700
3 | spouseName | Lucy
次のようなクエリのビューが必要です
SELECT E.*, EA1.ATTR_VALUE AS APPRAISAL_RATE, EA2.ATTR_VALUE AS SPOUSE_NAME FROM EMP E
LEFT JOIN EMP_ATTRIBUTES EA1 ON E.EMPNO=EA1.EMPNO AND EA1.ATTR_NAME='appraised'
LEFT JOIN EMP_ATTRIBUTES EA2 ON E.EMPNO=EA2.EMPNO AND EA2.ATTR_NAME='spouseName';
Expected Output
empno | ename | location | salary | APPRAISAL_RATE | SPOUSE_NAME
1 | Josh | LA | 1200 | 10% | NULL
2 | Joe | NY | 1000 | 12% | Amelia
3 | George | LA | 1500 | 25% | Lucy
私は試した
<view-entity entity-name="EmpAndEmpAttributesAndEmpAttributes"
package-name="com.proj.employee"
title="Employee and Employee Attribute and Employee Attribute">
<member-entity entity-alias="E" entity-name="Emp"/>
<member-entity entity-alias="EA1" entity-name="EmpAttributes"/>
<member-entity entity-alias="EA2" entity-name="EmpAttributes"/>
<alias-all entity-alias="E"/>
<alias-all entity-alias="EA1"/>
<alias-all entity-alias="EA2"/>
<view-link entity-alias="E" rel-entity-alias="EA1" rel-optional="true">
<key-map field-name="empno"/>
</view-link>
<entity-condition>
<condition-expr entity-alias="EA1" field-name="attrName" operator="equals" value="appraised" />
</entity-condition>
<view-link entity-alias="E" rel-entity-alias="EA2" rel-optional="true">
<key-map field-name="empno"/>
</view-link>
<entity-condition>
<condition-expr entity-alias="EA1" field-name="attrName" operator="equals" value="spouseName" />
</entity-condition>
</view-entity>
誰かが私に何が間違っているのか教えてくれますか? またはこの問題を解決する他の方法...