MyQSL 错误:Column 'customer_name' in field list is ambiguous

原创
2022/05/02 09:03
阅读数 493

执行 SQL:

    SELECT
        customer_name,
        COUNT(id) AS count_child
    FROM
        scrm_customer r
    LEFT JOIN scrm_contacts c ON
        r.contacts_id = c.contacts_id
    GROUP BY
        customer_name

出现错误: Column 'customer_name' in field list is ambiguous

原因是:scrm_customer 和 scrm_contacts 两张表都有 customer_name 字段,不知道按照哪张表的 customer_name 进行分组。

ambiguous = adj. 模棱两可的;含混不清的;不明确的

正确 SQL,多表联合查询,最后都加上表限定,不容易出错:

    SELECT
        r.customer_name,
        COUNT(id) AS count_child
    FROM
        scrm_customer r
    LEFT JOIN scrm_contacts c ON
        r.contacts_id = c.contacts_id
    GROUP BY
        r.customer_name
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部