select date_flag,category_flag,field,LAG(filed, 1) OVER (PARTITION BY category_flag ORDER BY date_flag) --同组前一个,LEAD(filed, 1) OVER (PARTITION BY category_flag ORDER BY date_flag) --同组后一个from table ;