gpt4 book ai didi

mysql - 从两个表中选择数据,mysql

转载 作者:行者123 更新时间:2023-11-29 08:05:23 24 4
gpt4 key购买 nike

我的数据库有两个表“客户”和“交易”。

客户表有 8 列,交易表有 4 列,

客户表主键是id,交易表没有主键,交易表中每个客户存在多条记录。

我需要从客户中选择 4 列,从交易中选择 3 列。

这里是查询:

query ='SELECT c.customer_id AS "Customer ID",
c.father_name AS "Father Name",
c.address AS Address,
c.phone_number AS "Phone Number",
c.mobile_number AS "Mobile Number",
c.id_proof AS "ID Proof",
c.area AS "Area",
c.ip_address AS "IP Address",
c.mac_address AS "MAC Address",
c.package_type AS "Package Type",
c.name AS Name,
c.activation_date AS "Activation Date",
c.status AS "Status",
c.installation_cost AS "Installation Cost",
c.totalamount_paid AS "Total Amount Paid",
c.monthly_amount AS "Monthly Amount",
c.lastpaid_date AS "Last Paid Date",
c.lastpaid_amount AS "Last Paid Amount",
c.nextpay_date AS "Next Pay Date",
c.totaldue_amount AS "Total Due Amount",
t.agent_id AS "Agent ID",
t.token_number AS "Token Number",
t.machine_id AS "Machine ID"
FROM customer c INNER JOIN transaction t ON c.customer_id = t.customer_id
WHERE DATE(t.paid_date)BETWEEN '" + fromDate + "'AND '" + toDate + "' ";

但问题是:

该记录在事务表中存在多少次,即其给出记录的次数,但我只需要一次。

我该怎么做?

最佳答案

... GROUP BY c.customer_id

您很可能想要对某些列进行求和或使用其他聚合函数。

关于mysql - 从两个表中选择数据,mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com