gpt4 book ai didi

mysql - 隐藏重复行sql phpmyadmin

转载 作者:行者123 更新时间:2023-11-28 23:39:33 26 4
gpt4 key购买 nike

我有关于重复行的问题。

enter image description here

我的目的是这样的:

enter image description here

先生,您能帮我查询一下吗?

我一直使用的代码如下:

select a.id_task1, b.id_task, b.task, b.cycle_sequence_number, c.cycle_sequence_number FROM task_table a LEFT OUTER JOIN billing_cycle b ON (a.id_task1=b.id_task) LEFT OUTER JOIN header c ON (b.cycle_sequence_number = c.cycle_sequence_number) where a.id_task1< 23 order by b.cycle_sequence_number DESC;

问候,-三-


对不起,先生,我忘记发布我的代码了:

select a.id_task1, b.id_task, b.task, b.cycle_sequence_number, c.cycle_sequence_number
FROM task_table a
LEFT OUTER JOIN billing_cycle b ON (a.id_task1=b.id_task)
LEFT OUTER JOIN header c ON (b.cycle_sequence_number = c.cycle_sequence_number)
where a.id_task1< 23
order by b.cycle_sequence_number DESC;

最佳答案

在关系数据库中,查询的结果是关系/表(“关系”和“表”是同义词)。因此,让我们为您的查询命名并使用group bys:

select id_task1, id_task, task, max(b.cycle_sequence_number) as b_cycle_sequence_number, max(c.cycle_sequence_number) as c_cycle_sequence_number
from (...) t
group by id_task1, id_task, task
order by b_cycle_sequence_number

您应该将 b.cycle_sequence_number 解释为 b_cycle_sequence_number 并将 c.cycle_sequence_number 解释为 c_cycle_sequence_number 以避免列名重复.很抱歉没有重写你的实际代码,但我拒绝从图片中输入你的代码。

编辑:真正的代码是:

select a.id_task1, b.id_task, b.task, b.cycle_sequence_number, c.cycle_sequence_number FROM task_table a LEFT OUTER JOIN billing_cycle b ON (a.id_task1=b.id_task) LEFT OUTER JOIN header c ON (b.cycle_sequence_number = c.cycle_sequence_number) where a.id_task1< 23 order by b.cycle_sequence_number DESC;

建议:

SELECT id_task1, id_task, task, max(b.cycle_sequence_number) as b_cycle_sequence_number, max(c.cycle_sequence_number) as c_cycle_sequence_number
FROM (SELECT a.id_task1, b.id_task, b.task, b.cycle_sequence_number as b_cycle_sequence_number, c.cycle_sequence_number as c_cycle_sequence_number
FROM task_table a
LEFT OUTER JOIN billing_cycle b
ON (a.id_task1=b.id_task)
LEFT OUTER JOIN header c
ON (b.cycle_sequence_number = c.cycle_sequence_number) where a.id_task1< 23) t
GROUP BY id_task1, id_task, task
ORDER BY b_cycle_sequence_number

关于mysql - 隐藏重复行sql phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34781454/

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