gpt4 book ai didi

oracle - 如何防止在选择查询中选择重复的行?

转载 作者:行者123 更新时间:2023-12-04 13:54:40 25 4
gpt4 key购买 nike

我已经获得了从Oracle数据库中选择关键数据的任务,但是我注意到我的选择返回了重复的行。我的报告不需要它们,但我不希望它们删除它们。有人可以帮忙获取我需要的数据吗?我尝试了以下代码,但这无济于事。

SELECT distinct bbp.SUBCAR "Treadwell",
bbp.BATCH_ID "Batch ID",
bcs.SILICON "Si",
bcs.SULPHUR "S",
bcs.MANGANESE "Mn",
bcs.PHOSPHORUS "P",
to_char(bcs.SAMPLE_TIME, 'dd-MON-yy hh24:MI') "Sample Time",
to_char(bbp.START_POUR, 'dd-MON-yy hh24:MI') "Start Pour Time",
to_char(bbp.END_POUR, 'dd-MON-yy hh24:MI') "End pour Time",
bofcs.temperature "Temperature"
FROM bof_chem_sample bcs, bof_batch_pour bbp, bof_celox_sample bofcs
WHERE bcs.SAMPLE_CODE= to_char('D1')
AND bbp.BATCH_ID=bcs.BATCH_ID
AND bcs.SAMPLE_TIME>=to_date('01-jan-10')

最佳答案

如果查看转换为SQL Server类型SQL的查询,您会发现 bofcs 表与其余数据之间没有任何关系。基本上,它会返回bofcs温度字段中的每条记录,这可能会产生重复的结果吗?

SELECT
bbp.SUBCAR "Treadwell",
bbp.BATCH_ID "Batch ID",
bcs.SILICON "Si",
bcs.SULPHUR "S",
bcs.MANGANESE "Mn",
bcs.PHOSPHORUS "P",
to_char(bcs.SAMPLE_TIME,'dd-MON-yy hh24:MI') "Sample Time",
to_char(bbp.START_POUR, 'dd-MON-yy hh24:MI') "Start Pour Time",
to_char(bbp.END_POUR, 'dd-MON-yy hh24:MI') "End pour Time",
bofcs.temperature "Temperature"
FROM
bof_chem_sample bcs,
INNER JOIN
bof_batch_pour bbp,
ON
bbp.BATCH_ID=bcs.BATCH_ID
INNER JOIN
bof_celox_sample bofcs
ON
**-- NO RELATION B/N BOFCS and the other tables????**
WHERE
bcs.SAMPLE_CODE= to_char('D1') AND
bcs.SAMPLE_TIME>=to_date('01-jan-10')

关于oracle - 如何防止在选择查询中选择重复的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6064431/

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