2015-03-03 62 views
-3

我得到一个错误,在SQLMySQL查询错误匹配数据

我有三个表

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 

in 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分别编号,t1_id的计数T1的多少t1_id元素的存在

意味着我必须在T1类ID和T2表同一类别ID与t1_id和T3 t1_t2_id我想算多少比赛在T2找到具有相同t1_t2_id

+3

什么是错误?你目前的sql语句是什么? – 2015-03-03 12:18:32

回答

-2

我认为这会为你工作(数如果T2 T1 IDS):

SELECT count(*) from t1,t3 where t1.id=t2.t1_id; 
+0

你在使用t2的时候,t2是不是你选择的部分? – 2015-03-03 12:38:43

+0

也避免使用隐式连接,它们已被弃用 – jean 2015-03-03 12:48:17

0

不知道我正确理解你在说什么,但尝试:

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