PHP mysql从数据库的三个表中选择信息



客户搜索按卡号进行(见表A客户),我使用的代码是:

$id = $_POST['card_number'];
SELECT e.*, sum(u.points) as points, sum(u.cost) as cost,
max(date_format(u.date_points, '%e/%c/%Y')) as data
FROM `customer` AS e 
INNER JOIN `points` AS u ON e.id_customer = u.id_customer 
where card_number='$id'

现在我公开我的表,然后我解释我的问题

表A客户:它包含成员

的信息。
card_number12345678909876543210

如果你想在一个请求中获得你需要的所有信息,你可以像这样创建子请求:

SELECT
c.*,
(
SELECT
SUM(p.points)
FROM
points p
WHERE
p.id_customer = c.id_customer
) AS points,
(
SELECT
SUM(d.points)
FROM
deducted_points d
WHERE
d.id_customer = c.id_customer
) AS deducted_points
FROM
customer c;

结果如下

tbody> <<tr>2
id_customernamecard_numberpointsdeducted_points
1卢卡1234567890255
标记98765432104515