MySQL 从 SQL 过度转换为 MySQL

MySQL Over Convert from SQL to MySQL

谁能帮我把这个SQL语句改成MySQL。 它被用于服务器端分页的 jQuery 数据表。 我试过使用

@curRank := @curRank + 1 AS rank

而不是

row_number() OVER (ORDER BY  item_id  asc) AS RowNumber

但我一直收到语法错误

             CREATE TEMPORARY TABLE IF NOT EXISTS temp1 AS (SELECT * INTO temp1 FROM item where BLOCKED='0');            

            SELECT *
            FROM
                (SELECT row_number() OVER (ORDER BY  item_id  asc) AS RowNumber , *
                    FROM
                        (SELECT (SELECT count(temp1.NO)
                                FROM
                                    temp1) AS TotalRows
                            , ( SELECT  count(NO) FROM temp1  ) AS TotalDisplayRows ,*
                        FROM
                            temp1  ) RawResults) Results
            WHERE
                RowNumber BETWEEN 1 AND 10

感谢您的帮助,这里是查询。但是我如何 return TotalRows 和 TotalDisplayRows 到数据中?我不得不手动添加 item_id 和描述。我输出的列是 RowNumber、Item_Id、Description。我还需要 TotalRows amd TotalDisplayRows

设置@rn := 0;

SELECT *
              FROM (SELECT (@rn := @rn + 1) AS RowNumber,item_id,description
                    FROM
                        (SELECT (SELECT count(item.item_id)
                                FROM
                                    item) AS TotalRows
                            , ( SELECT  count(item_id) FROM item  ) AS TotalDisplayRows ,item_id,description
                        FROM
                            item  ) RawResults

                        ) Results
            WHERE
                RowNumber BETWEEN 1 AND 10

您可以使用变量:

CREATE TEMPORARY TABLE IF NOT EXISTS temp1 AS (SELECT * INTO temp1 FROM item where BLOCKED='0');            
    SELECT *
    FROM (SELECT (@rn := @rn + 1) AS RowNumber , *
          FROM (SELECT (SELECT count(temp1.NO)
                        FROM temp1
                       ) AS TotalRows,
                       (SELECT count(NO) FROM temp1  ) AS TotalDisplayRows ,*
                FROM temp1 
               ) RawResults CROSS JOIN
               (SELECT @rn := 0) vars
          ORDER BY item_id
          ) Results
    WHERE RowNumber BETWEEN 1 AND 10

如果您实际上不需要 table 中的 RowNumber 列,您可以只使用 limitoffset

SELECT * FROM (SELECT (@rn := @rn + 1) AS RowNumber,item_id,description
FROM
    (SELECT (SELECT count(item.item_id)
            FROM
                item) AS TotalRows
        , ( SELECT  count(item_id) FROM item  ) AS TotalDisplayRows ,item_id,description
    FROM
        item  ) RawResults
    ) Results 
    WHERE RowNumber BETWEEN 1 AND 10