我有两个表 emp 和 emp_attributes 我想在其中进行条件连接
雇员
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>
有人让我知道我做错了什么?或任何其他解决此问题的方法...