(针对 SQL 语言的问题,用这个标题。请用 Ctrl+Y 砍掉这行) 数据库名称:MySQL 数据库版本:MyWorkbench 8.0 内容/问题描述: 最近初学SQL, 想请教以下一个问题。 共有两个表(Customer/Customer_Order) https://i.imgur.com/KuUAAKS.jpg https://i.imgur.com/EbQLT4V.jpg 题目:需要返回cust_name, total number of orders (计算Customer_order里每个cust_ id的数量),包含没order的cust_name (显示0),必须使用correlated subquery和scalar 。 感谢看完那么长的问题,我目前怎么写都顶多返回‘不含0’的版本,苦无计策! 附上我写的不含0版本: SELECT c.cust_name, CO.cnt as total_number_of_orders FROM Customer c, (SELECT co.cust_id, count(co.cust_id) as cnt FROM Customer_Order co GROUP BY co.cust_id) CO WHERE c.cust_id= CO.cust_id GROUP BY c.cust_id; 希望板上高手能提点提点!谢谢!!