MySQL高级分组排序

想要根据用户分组,以该用户的下单时间为降序,提取所有用户的第二个订单信息。
这属于分组排序,在Oracle有内置函数可以实现,而在mysql就有点麻烦:

CREATE TABLE user_orders (orders_id INT UNSIGNED NOT NULL, user_id INT UNSIGNED NOT NULL, add_time INT UNSIGNED NOT NULL, PRIMARY KEY(orders_id), KEY(user_id), KEY(add_time) )ENGINE=INNODB DEFAULT CHARSET utf8 COMMENT 'mysql实现分组排序测试表'; INSERT INTO `user_orders` (`orders_id`, `user_id`, `add_time`) VALUES('1','1','1'); INSERT INTO `user_orders` (`orders_id`, `user_id`, `add_time`) VALUES('2','1','2'); INSERT INTO `user_orders` (`orders_id`, `user_id`, `add_time`) VALUES('3','1','3'); INSERT INTO `user_orders` (`orders_id`, `user_id`, `add_time`) VALUES('4','2','1'); INSERT INTO `user_orders` (`orders_id`, `

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyxjwz.html