pb/sqlite3连接比较表

wljmcqd8  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(308)

我有两张table:
t1级

"IdT1;i1T1,n2T1
1;123;n2T1
2;234;n3T1
3;345;n4T1
4;678;n1T1
5;123;n2T1
6;234;n3T1

t2级

"idT2;n1T2;n2T2;i1T2
1;1n1T2;2n1T2;123
2;1n2T2;2n1T2;234
3;1n3T2;2n1T2;345
4;1n4T2;2n1T2;456
5;1n5T2;2n1T2;567
6;1n6T2;2n1T2;678

在sqlite3中

$req = $db -> prepare("SELECT T2.n1T2, T2.n2T2,
    //COUNT(*)
    FROM T1
    INNER JOIN T2 ON T1.idT2 = T2.idT2
");

if ($res = $req->execute()) {
    $arr = $res->fetchArray();
    var_dump($arr);
}

我搜索n1t2和n2t2名称,即i1t1和i1t2之间相同值的计数

example:

1n1T2;2n1T2;2
1n2T2;2n2T2;2
1n3T2;2n1T2;1
...

i var\u dump for display,in wait best方法

a11xaf1n

a11xaf1n1#

看起来您需要一个联接和聚合:

select t2.n1t2, t2.n2t2, count(*) cnt
from t1
inner join t2 on t2.i1t2 = t1.i1t1
group by t2.n1t2, t2.n2t2

相关问题