-4

我需要一些关于 PHP 查询的帮助。我有 5 个表:供款、员工、公司客户和帐户。

客户和贡献通过帐户加入的联结。客户再次通过员工与公司连接。

公司加入贡献即

[(Table client---id_client).
 (Table account --id_account,id_client,id_contribution).
 (Table contribution---id contribution,id_account,id_firm).
 (Table firm---id_firm).
 (Table employee---id_employee,id_firm,id_client)]

我如何检索特定客户的贡献?

4

1 回答 1

1

您的查询似乎不需要所有五个表。尝试这个:

SELECT * 
FROM contribution 
  INNER JOIN account ON account.id_account = contribution.id_account
WHERE account.id_client = xyz;

xyz是您想要为其贡献的客户 ID。

如果您还想获取员工信息,您也可以加入该表:

SELECT * 
FROM contribution 
  INNER JOIN account ON account.id_account = contribution.id_account
  INNER JOIN employee ON employee.id_client = account.id_client
WHERE account.id_client = xyz;
于 2013-05-11T14:55:59.140 回答