该查询旨在显示 tbltransactions 中按 customerid 分组的所有记录,并从 tblcustomers 中选择两个表的 customerid 匹配的客户名称。
select
a.customerid,
sum(transactionamount) as transactionamount,
b.customername
from
tbltransactions a,
tblcustomers b
where
a.customerid = b.customerid
group by customerid
order by b.customername
此查询是否确保 tbltransactions 中的所有记录都正确显示。我是 MySQL 和 php 新手。谢谢
其次:
当我添加“a”时。 to sum(transactionamount) as transactionamount"它会产生错误为什么会这样?此外它是什么类型的联接查询。
最佳答案
试试这个..
select a.customerid, sum(transactionamount) as transactionamount, b.customername from tbltransactions a INNER JOIN tblcustomers b ON a.customerid = b.customerid group by customerid order by b.customername
关于mysql - 此 SQL 查询是否会产生正确的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24358341/