以下语句更新名为“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
)
);
我没有更新列,而是希望收到一条SELECT语句,该语句提供每行的读数(如果它是UPDATE语句,则会更新)。
有关表格性质和代码目标的更多信息(如果需要)在这里: Efficient assignment of percentile/rank in MYSQL
答案 0 :(得分:2)
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
答案 1 :(得分:0)
这个怎么样?
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;