在多表查询时,查询出的结果列字段在多表中重复出现,需要使用别名.列名查询。
特殊情况是,重复字段出现在${ew.customSqlSegment}里面,导致无法更改,这时可以修改from后表使其不包含重复字段。如下:
@Select("SELECT a.*,b.NAME as clusterName,b.PROM_BASE_URL as promBaseUrl, c.VERSION as subVersion FROM MCP_VIRTUAL_MACHINE AS a " +
"left join MCP_CLUSTER AS b on a.CLUSTER_ID = b.ID left join (SELECT ID,VERSION FROM MCP_IMAGE) AS c on a.IMAGE_ID = c.ID ${ew.customSqlSegment}")
IPage<VirtualMachine> getRecyclePageList(IPage<VirtualMachine> page, @Param(WRAPPER) Wrapper<VirtualMachine> wrapper);
上述多表查询中MCP_VIRTUAL_MACHINE和MCP_IMAGE表中都含有STATUS字段,这时修改MCP_IMAGE表范围为需要字段即可。