2022-12-17:订单最多的客户。以下数据,结果输出3。请问sql语句如何写?
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`order_number` int(11) NOT NULL,
`customer_number` int(11) NOT NULL,
PRIMARY KEY (`order_number`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `orders` VALUES ('1', '1');
INSERT INTO `orders` VALUES ('2', '2');
INSERT INTO `orders` VALUES ('3', '3');
INSERT INTO `orders` VALUES ('4', '3');
答案2022-12-17:
sql语句如下:
SELECT
customer_number
FROM
orders
GROUP BY customer_number
ORDER BY COUNT(*) DESC
LIMIT 1