【问题标题】:mysql query error matching datamysql查询错误匹配数据
【发布时间】:2015-03-03 12:12:12
【问题描述】:

我在 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_id 中的 t1_id 元素分别有多少个 id, t1_id in t1_t2_id

意味着我在 t1 中有类别 id,在 t2 表中有相同的类别 id,t1_id 和 t3 t1_t2_id 我想计算在 t2 中找到的具有相同 t1_t2_id 的匹配数

【问题讨论】:

  • 错误是什么?你当前的sql语句是什么?

标签: php mysql sql


【解决方案1】:

不确定我是否完全理解您在说什么,但请尝试:

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

【讨论】:

    【解决方案2】:

    我认为这对你有用(如果 t1 ids 在 t2 中,则为数字):

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

    【讨论】:

    • 当 t2 不属于您的选择时,您在哪里使用 t2?
    • 也避免使用隐式连接,它们已被弃用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 2012-04-08
    • 1970-01-01
    相关资源
    最近更新 更多