Mysql 选择总计和名称

标签 mysql

列出客户的名字、姓氏和花费的总金额(注意:花费的金额是订单小计 + 税费 + tblorder 表中的运输费用)。

我有这个代码(但值都是一样的:

Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder,tblcust
group by name

my queries

最佳答案

这应该可以做到:

Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder a
inner join tblcust b ON a.custId=b.custId
group by name;

您没有定义要加入表格的内容。

在您的代码风格中,这将是:

Select CONCAT(firstname, ' ' ,lastname) as name, sum(ordersubtotal + ordertax + ordershipcost) as AmountSpent
From tblorder a,tblcust b
where a.custId=b.custId
group by name;

(两者应该给出相同的结果)

关于Mysql 选择总计和名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29404364/

相关文章:

PHP Mysql表信息

mysql - zpanel安装-重装mysql问题-CentOS-6.4 zpanel-10.1.0

mysql - 在文本文件中添加两列并加载到 sql

sql - 多对多自引用选择sql查询

php - 有没有像 EtherPad Using php and mySql 这样的开源项目?

php - 为什么用php创建的excel文件与浏览器中的表格不一样?

mysql - 使用 IF 语句进行查询

mysql - 我应该在数据库中复制数据吗?

php - 将大型 (4 GB) CSV 插入 Mysql 数据库(Web 服务器)

mysql - 如何使用子字符串编写sql查询