开发者

Convert UPDATE statement to a SELECT statement

The following statement updates a column in a table named 'test'.

UPDATE test AS t
INNER JOIN test AS q ON(
    q.ptime = t.ptime
)
SET t.slope_Percentile =(
    (
        SELECT
            count(*)
        FROM
            (
                SELECT
                    *
                FROM
                    test
            )AS t1
        WHERE
            t1.slope < t.slope
    )* 100 /(
        SELECT
            count(*)
        FROM
            (
                SELECT
                    *
                FROM
                    test
            ) AS tz
    )
);

Instead of updating th开发者_运维百科e column I would like to receive a SELECT statement that gives a readout of each row (that would be updated if it was an UPDATE statement).

More information (if needed) about the nature of the tables and the goal of the code is here: Efficient assignment of percentile/rank in MYSQL


SELECT t.ptime,
( 
    ( 
        SELECT 
            count(*) 
        FROM 
            ( 
                SELECT 
                    * 
                FROM 
                    test 
            )AS t1 
        WHERE 
            t1.slope < t.slope 
    )* 100 /( 
        SELECT 
            count(*) 
        FROM 
            ( 
                SELECT 
                    * 
                FROM 
                    test 
            ) AS tz 
    ) 
)  AS slope_Percentile
 FROM test AS t 
--INNER JOIN test AS q ON
--q.ptime = t.ptime 


How about this?

SELECT *, (
    (SELECT count(*)
    FROM test AS t1
    WHERE t1.slope < t.slope) * 100 /
    (SELECT count(*)
    FROM test as tz)) as newvalue
FROM test AS t;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜