你如何从mysql中选择每第n行

2021-11-20 00:00:00 mysql

我需要提取数据库中的一系列值来创建折线图.因为我不需要高分辨率,所以我想通过从数据库中选择每 5 行来重新采样数据.

I have a series of values in a database that I need to pull to create a line chart. Because i dont require high resolution I would like to resample the data by selecting every 5th row from the database.

推荐答案

SELECT * 
FROM ( 
    SELECT 
        @row := @row +1 AS rownum, [column name] 
    FROM ( 
        SELECT @row :=0) r, [table name] 
    ) ranked 
WHERE rownum % [n] = 1 

相关文章