考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

某电子商务网站的数据库中有两个数据表,一个记录了所有商品的基本信息(包括商品ID、商品名称、价格,表名为products),另一个记录了顾客的订单信息(包括订单ID、商品ID、顾客ID、购买数量,表名为orders)。数据分析师需要查询每个商品的总销售数量,并且按照销售数量从高到低排序。以下哪些SQL查询语句不能够正确实现这一目标()
A. SELECT products.product_name, SUM(orders.quantity) FROM products INNER JOIN orders ON products.product_id = orders.product_id GROUP BY products.product_name ORDER BY SUM(orders.quantity) DESC;
B. SELECT products.product_name, SUM(orders.quantity) FROM products LEFT JOIN orders ON products.product_id = orders.product_id GROUP BY products.product_name ORDER BY SUM(orders.quantity) DESC;
C. SELECT products.product_name, SUM(orders.quantity) FROM products RIGHT JOIN orders ON products.product_id = orders.product_id GROUP BY products.product_name ORDER BY SUM(orders.quantity) DESC;
D. SELECT products.product_name, COUNT(orders.product_id) FROM products LEFT JOIN orders ON products.product_id = orders.product_id GROUP BY products.product_name ORDER BY COUNT(orders.product_id) DESC;
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

A正确。INNER JOIN 会丢失没有订单的商品,不符合题意。B错误。左连接(LEFT JOIN)会返回所有商品的信息,即使某些商品没有订单记录,SUM 函数会自动忽略 NULL 值,仍然计算总销售数量,并按照总销售数量排序。C正确。RIGHT JOIN 以 orders 表为主表,可能导致 products 表中没有订单的商品被排除。D正确。COUNT(orders.product_id) 计算的是每个商品的订单记录数,而不是销售数量。应使用 SUM(orders.quantity) 来计算总销售数量。