gpt4 book ai didi

mysql - 在 JOIN 上排除 MySQL 中的结果

转载 作者:行者123 更新时间:2023-11-30 00:57:29 25 4
gpt4 key购买 nike

下面是我的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,例如:(234,234) (71,71) (445,445)。线

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”也没有图像则采用默认的“无图像” ”。显然 if-else 在 join 语句中是不可能的。当两个表都包含图像时,它会同时获取我不想要的图像。我需要这个用于 Birt 报告,我们不想在报告上显示错误的图像。我很乐意提供任何提示。

最佳答案

你可以只添加一个吗?将有问题的行更改为:

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
)

关于mysql - 在 JOIN 上排除 MySQL 中的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20428693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com