下面是我的MySQL语句:
select
tableT.id,
tableTGroupName,
tableTGroupSortOrder,
tableT_group.Deleted as tableTGroupDeleted,
tableTSuiteName,
tableTSuiteSortOrder,
tableT_suite.Deleted as tableTSuiteDeleted,
tableTCaseName,
tableTCaseSortOrder,
tableT_case.Deleted as tableTCaseDeleted,
DbPackageName,
E_imgLR as Eimg,
R_imgLR as Rimg,
tableTResultState,
tableTResultComment
from
tableT_result
inner join tableT on tableT_id = tableT.id
inner join tableT_run on tableT_run_id = tableT_run.id
inner join db_package on db_package_id = db_package.id
inner join tableT_case on tableT_case_id = tableT_case.id
inner join tableT_suite on tableT_suite_id = tableT_suite.id
inner join tableT_group on tableT_group_id = tableT_group.id
left outer join E_img_lo_r on tableT_case.e_img_id = E_img_lo_r.e_img_id or tableT_suite.e_img_id = E_img_lo_r.e_img_id -- Problematic line
left outer join result_image_low_res on tableT_result.result_image_id = result_image_low_res.result_image_id
where
db_package_label_id = ?
order by
tableTGroupSortOrder,
tableTSuiteSortOrder,
tableTCaseSortOrder
最后,这句话给了我16行,其中3行(结果)是多余的。3 x 2行具有相同的id,如:(234234)(71,71)(445445)。线路
left outer join E_img_lo_r on tableT_case.e_img_id = E_img_lo_r.e_img_id or tableT_suite.e_img_id = E_img_lo_r.e_img_id
因此,我可以使用DISTINCT来消除重复的ID,但行的内容不相同。这就是为什么我不想消除必要的争吵。
我的目的首先是检查"tableT_case"是否有图像,如果有,请使用它,如果没有使用"tableT_suite"中的图像,如果"tableT_suite"也没有图像,则采用默认的"无图像"。Afaik if else在联接语句上不可能。当两个表都包含一个图像时,它会同时获取我不想要的图像。我需要这个来做出生报告,我们不想在报告上显示错误的图像。如果能给我小费,我会很高兴的。
您能添加一个and
吗?将有问题的行更改为:
left outer join E_img_lo_r
on
tableT_case.e_img_id = E_img_lo_r.e_img_id
or
(
tableT_case.e_img_id != E_img_lo_r.e_img_id
and
tableT_suite.e_img_id = E_img_lo_r.e_img_id
)