mysql 查询所有数据,每条数据附带前一条指定列

分享一条大神写的sql,查询所有数据,每条数据附带前一条指定列:

SELECT
    f.ts_code,
    @prev AS pre_adj_factor,
    f.trade_date,
    @prev := f.adj_factor AS adj_factor 
FROM
    ( SELECT @prev := NULL ) AS i,
    syn_factors AS f 
WHERE
    ts_code = '000001.SZ' 
ORDER BY
    f.trade_date

你可能感兴趣的:(mysql 查询所有数据,每条数据附带前一条指定列)