MySQL选择并加入

MySQL选择并加入,mysql,join,Mysql,Join,我有两个表Customers和CDR_Customers(这些只是字段的一个示例): 我想要实现的是从CDR_Customers table=4中选择具有相同I_父项和I_服务的所有“客户”中的总“收费金额”进行查询 我尝试编写此查询,但似乎不正确: mysql> select sum(a.charged_amount), b.i_parent from CDR_Customers a join Customers b on a.i_customer=b.i_customer where

我有两个表Customers和CDR_Customers(这些只是字段的一个示例):

我想要实现的是从CDR_Customers table=4中选择具有相同I_父项和I_服务的所有“客户”中的总“收费金额”进行查询

我尝试编写此查询,但似乎不正确:

mysql> select sum(a.charged_amount), b.i_parent from CDR_Customers a join Customers b on a.i_customer=b.i_customer where b.i_parent=234 and i_service = 4;
+-----------------------+----------+
| sum(a.charged_amount) | i_parent |
+-----------------------+----------+
|                  NULL |     NULL |
+-----------------------+----------+

您可以提出建议吗?< /P> <代码> A.IuCube=266 B.IuCube=64</CODE>,聚合函数将总是在您喜欢的Lead Read中返回,考虑以下简单的两步过程:1。如果您还没有这样做,请提供适当的DDL(和/或SQLFIDLE),以便我们可以更轻松地复制问题。2.如果尚未这样做,请提供与步骤1中提供的信息相对应的所需结果集。您的陈述是正确的。结果为null,因为Customers表中的字段i_customer值为266,而CDR_Customers表中的字段i_customer值为64。只有当这些值相等时,JOIN子句才会返回这些值。

mysql> select sum(a.charged_amount), b.i_parent from CDR_Customers a join Customers b on a.i_customer=b.i_customer where b.i_parent=234 and i_service = 4;
+-----------------------+----------+
| sum(a.charged_amount) | i_parent |
+-----------------------+----------+
|                  NULL |     NULL |
+-----------------------+----------+