查找第二大数字

max()

1 2
SELECT max(sid) FROM `tbl_test` where sid < (SELECT max(sid) FROM `tbl_test`); SELECT max(sid) FROM `tbl_test` where sid != (SELECT max(sid) FROM `tbl_test`);

order by、group by

1 2
SELECT min(sid) FROM (SELECT sid FROM `tbl_test` order BY sid DESC limit 2) as tmp; SELECT min(sid) FROM (SELECT sid FROM `tbl_test` group BY sid DESC limit 2) as tmp;

浙ICP备11005866号-8