我在sql 中遇到错误
我有三张桌子
T1、t2、t3
在t1
id name
1 a
2 b
3 c
4 d
5 e
在t2
t1_id name
4 sac
2 sau
4 rah
4 seh
1 kaif
5 zah
6 aas
8 ram
在t3
t1_t2_id name count lif_lin
1 Eve 2 no
2 sun 1 no
3 mon 0 no
4 tue 3 no
5 wed 1 no
6 thu 1 no
我想计算t1_t2_id 中id、t1_id的t1中分别存在多少t1_id元素
平均而言,我在t1中有类别id,在t2表中有相同的类别id,具有t1_id和t3 t1_t2_id,并且我想计算在t2中找到的具有相同t1_t2_id 的匹配数量
不确定我是否完全理解你的意思,但请尝试:
SELECT count(a.id)
from t1 a
join t2 b on a.id = b.t1_id
join t3 c on a.id = c.t1_t2_id
我认为这将适用于您(如果t1在t2中为id,则为数字):
SELECT count(*) from t1,t3 where t1.id=t2.t1_id;