Meta VO 面试真题解析:书店销售统计与邀请关系 SQL 题

35次阅读
没有评论

Write a query to find the total value of sales and the number of unique paying customers, grouped and sorted in descending order by payment type.

Existing customers can invite other people to sign up to the bookstore. Find the IDs of the top 5 customers, ordered by the average payment per book made by the people they invited.

Find the total number of authors. What percentage of them have a website URL that contains .com, and what percentage never made a sale?

Schema:

books(book_id INT KEY, title VARCHAR, author_id INT, publication_date DATE, category VARCHAR, price DOUBLE)
authors(author_id INT KEY, first_name VARCHAR, last_name VARCHAR, birthday DATE, website_url VARCHAR)
transactions(transaction_id INT KEY, book_id INT, customer_id INT, payment_amount DOUBLE, book_count INT, tax_rate DOUBLE, discount_rate DOUBLE, transaction_date DATE, payment_type VARCHAR)
customers(customer_id INT KEY, first_name VARCHAR, last_name VARCHAR, registration_date DATE, interested_in_categories VARCHAR, is_rewards_member BOOLEAN, invited_by_customer_id INT)

这道题本质上是一个书店业务场景下的 SQL 统计题,核心考察分组聚合、去重计数,以及通过外键关系做多表关联分析。第一问需要按 payment_type 分组,汇总销售额并统计唯一付费客户数;第二问需要根据 customers 表中的 invited_by_customer_id 找出邀请关系,再计算被邀请用户产生的每本书平均支付金额并排序取前 5;第三问则围绕 authors 表做整体统计,计算作者总数、网站包含 .com 的比例,以及从未产生销售的作者比例。

正文完
 0