有三个表,书籍表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`.`name` AS `customer`,`customer`.`age` AS `age`, `book`.`name` AS `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 查询出的结果如下: