简体   繁体   中英

Yii2: How to select last second (penultimate) record in the table?

How to select last second record (that goes before the last one) from the table? Next statement works OK, but selects the last record:

SystemStatisticsHistory::find()->orderBy(['id' => SORT_DESC])->one();

Thank you!

Add an OFFSET clause:

SystemStatisticsHistory::find()->orderBy(['id' => SORT_DESC])->offset(1)->one();

http://www.yiiframework.com/doc-2.0/yii-db-querytrait.html#offset()-detail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM