将查询从mysql v8.0转换为v5.6

niknxzdl  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(236)

我开发了一个基于mysql v8.0的系统,不幸的是,我需要对web hostings中最常用的版本v5.6进行降级。
我的问题几乎都是这样的:

SELECT tb_d.*, id_classification 
FROM (
    SELECT ROW_NUMBER() OVER(PARTITION BY '1' ORDER BY od_category ASC, $order_by_gp_mid) AS row_final, tb_c.*
    FROM (
        SELECT ROW_NUMBER() OVER(PARTITION BY id_category ORDER BY MOD(`row` * $prime_group, 512)) AS rd_category, tb_b.*
        FROM (
            SELECT ROW_NUMBER() OVER(PARTITION BY '1' ORDER BY od_category ASC, $order_by_gp_mid) AS `row`, tb_a.*
            FROM (
                SELECT ROW_NUMBER() OVER (PARTITION BY id_category ORDER BY od_category ASC, tb_x.$order_by_gp_mid) AS rn_category, tb_x.*
                FROM (
                    SELECT
                    1, od_category, id_category, `group`, category,
                    id_post, thumbnail, head, visibility, created_datetime, `view`, yeslike, save,
                    lk_post_category_pic_uvw.fk_pic, 
                    ROUND((yeslike + total_save) / view, 3) AS rank_ratio

                    FROM tb_category

                    JOIN (
                        SELECT fk_post, fk_category, fk_pic
                        FROM lk_post_category_pic

                        UNION

                        SELECT fk_post, `from`, fk_pic
                        FROM lk_post_model_pic
                        JOIN tb_model ON tb_model.id_model = lk_post_model_pic.fk_model
                        WHERE `from` != ''
                    ) AS lk_post_category_pic_uvw   ON lk_post_category_pic_uvw.fk_category = tb_category.id_category
                    JOIN tb_post                    ON lk_post_category_pic_uvw.fk_post     = tb_post.id_post
                    LEFT JOIN vw_total_save_by_post ON vw_total_save_by_post.fk_post    = tb_post.id_post

                    WHERE visibility = 'show'

                ) AS tb_x
            ) AS tb_a

            WHERE rn_category <= 35
        ) AS tb_b
    ) AS tb_c

    WHERE rd_category = 1
) AS tb_d

JOIN lk_post_classification_pic ON tb_d.id_post = lk_post_classification_pic.fk_post 
JOIN tb_classification          ON lk_post_classification_pic.fk_classification = tb_classification.id_classification

变量$order\ by\ U gp\ U mid可以假设以下值:

$order_by_gp_mid = 'created_datetime DESC';
$order_by_gp_mid = 'rank_ratio DESC';
$order_by_gp_mid = '`view` DESC';
$order_by_gp_mid = 'created_datetime DESC';
$order_by_gp_mid = 'created_datetime ASC';

所以,这里最大的问题是上面的行数(partitionbyblabla…)。
我需要为MySQL5.6重写这个查询,以及其他许多查询。
我已经在stackoverflow中读到了很多关于这个的主题,但是我不知道怎么做,因为我的查询非常复杂。
所以,我不知道该怎么办了,我已经完全厌倦了电脑编程。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题