gpt4 book ai didi

android - 如果特定列值重复,则行并集

转载 作者:行者123 更新时间:2023-11-29 21:37:08 24 4
gpt4 key购买 nike

例如我有 3 个表:

table1(id,value) table2(id,fk,value) table3(id,fk,value)

table2 和 table3 是 table1 的子级。

我有以下 SQL 查询:

query = "SELECT" +
" t1.id AS _id," +
" t2.id AS t2_id," +
" t2.fk as t2_fk," +
" t2.value as t2_value," +
" t3.id AS t3_id," +
" t3.fk as t3_fk," +
" t3.value as t3_value," +
" FROM t1 table1" +
" INNER JOIN table2 t2 ON t1.id = t2.fk" +
" INNER JOIN table3 t3 ON t1.id = t3.fk" +
" WHERE t2.value like '%"+lookingFor+"%' LIMIT 10";

光标给出以下结果:

enter image description here

如何制作:

enter image description here

我的目的是避免值重复,同时将所有 t3_value 收集在一个地方。我怎样才能做到这一点?

最佳答案

试试这个:

query = "SELECT" +
" t1.id AS _id," +
" t2.id AS t2_id," +
" t2.fk as t2_fk," +
" t2.value as t2_value," +
" GROUP_CONCAT(t3.value) as t3_value," +
" FROM t1 table1" +
" INNER JOIN table2 t2 ON t1.id = t2.fk" +
" INNER JOIN table3 t3 ON t1.id = t3.fk" +
" WHERE t2.value like '%"+lookingFor+"%'
GROUP BY t1.id, t2.id, t2.fk, t2.value LIMIT 10 ";

并了解您想要的是“GROUP_CONCAT(X,Y)” - 部分引用 here .

关于android - 如果特定列值重复,则行并集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18172174/

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