查询每个年龄的顾客消费金额数的SQL语句

xiaoxiao2021-02-28  88

有三个表,书籍表book(id,name,price)和顾客表customer(id,name,age)以及订单表orders(id,bookid,customerid)。

请写出查询每个年龄的顾客消费金额数的SQL语句。

书籍表:

顾客表:

订单表:

[sql]  view plain  copy   select `orders`.`id` AS `id`,`orders`.`bookid` AS `bookid`,`orders`.`customerid` AS `customerid`,   `customer`.`nameAS `customer`,`customer`.`age` AS `age`,   `book`.`nameAS `book`,`book`.`price` AS `price` from ((`orders` join `customer`) join `book`)    where ((`orders`.`bookid` = `book`.`id`) and (`orders`.`customerid` = `customer`.`id`))   查询出的订单详情数据如下:

查询每个年龄的顾客消费金额数的SQL语句如下:

[sql]  view plain  copy   SELECT SUM(price),age from    (SELECT price,age from orders,book,customer    where orders.bookid=book.id and orders.customerid=customer.id)    AS a GROUP BY age   查询出的结果如下:

转载请注明原文地址: https://www.6miu.com/read-36492.html

最新回复(0)