mysql - 需要知道如何选择购买价格大于100的客户名称

标签 mysql sql sum where-clause having

我有一个sql作业。我建立了一个小型数据库,有3个表(如图)。我需要选择上个月内购买超过100的客户名称。所有购买都是分开的。

我尝试使用 SUM

SELECT  customer.CustomerName
FROM customer INNER JOIN
     sales
     ON customer.id=sales.CustomerId
HAVING SUM(sales.SalesPrice > 100)  

在我的数据库中,有客户的销售价格总和大于0,但SQL返回空白输出enter image description here

最佳答案

试试这个:

SELECT customer.customerName FROM customer 
INNER JOIN sales ON customer.id = sales.customerId
GROUP BY customerName
HAVING SUM(sales.SalesPrice) > 100;

关于mysql - 需要知道如何选择购买价格大于100的客户名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57219152/

相关文章:

java - 我试图让用户将数字输入到 ArrayList 中。如果用户输入 0,则对数字求和并平均

php - 使用 PDO 变量将 $_POST 值传递到函数参数中

mysql - 在 MariaDB 数据库中授予权限

mysql - 可以以任何方式选择子选择中的别名

MySqlConnection' 在命名空间'MySql.Data.MySqlClient [Visual Basic -VS2008] 中不明确

mysql - 根据日期获取记录(最近30天)

mysql - 在具有相同值的多个实例的 SQL 中选择随机

mysql - MySQL 中何时使用单引号、双引号和反引号

groovy - Groovy 中 2 个列表的内容求和

php - SUM 行字段 MEDOO