无法设置 Percent_rank() - 默认为 0.0
Cannot set Percent_rank() - defaults to 0.0
我正在尝试设置一列,但结果每行最终都为 0.0。
如果我在 SELECT 中使用相同的语法(其中的 select 部分),结果会正确显示。
UPDATE table1
SET ranking = (SELECT
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC)
from table1
group by store_id)
这个可以实现吗?
子查询:
SELECT PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC)
from table1
group by store_id
returns 每个 store_id
1 行,SQLite 只选择一个并用该行的值 PERCENT_RANK()
更新 table.[=25 的所有行=]
您必须将子查询与 table1
相关联
UPDATE table1
SET ranking = (
SELECT pr
FROM (
SELECT store_id,
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC) pr
FROM table1
GROUP BY store_id
) t
WHERE table1.store_id = t.store_id
);
或者,如果您的 SQLite 版本是 3.33.0,请使用 UPDATE...FROM...
语法:
UPDATE table1 AS t1
SET ranking = t.pr
FROM (
SELECT store_id,
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC) pr
FROM table1
GROUP BY store_id
) t
WHERE t1.store_id = t.store_id;
我正在尝试设置一列,但结果每行最终都为 0.0。 如果我在 SELECT 中使用相同的语法(其中的 select 部分),结果会正确显示。
UPDATE table1
SET ranking = (SELECT
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC)
from table1
group by store_id)
这个可以实现吗?
子查询:
SELECT PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC)
from table1
group by store_id
returns 每个 store_id
1 行,SQLite 只选择一个并用该行的值 PERCENT_RANK()
更新 table.[=25 的所有行=]
您必须将子查询与 table1
UPDATE table1
SET ranking = (
SELECT pr
FROM (
SELECT store_id,
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC) pr
FROM table1
GROUP BY store_id
) t
WHERE table1.store_id = t.store_id
);
或者,如果您的 SQLite 版本是 3.33.0,请使用 UPDATE...FROM...
语法:
UPDATE table1 AS t1
SET ranking = t.pr
FROM (
SELECT store_id,
PERCENT_RANK() OVER(PARTITION BY city ORDER BY sales DESC) pr
FROM table1
GROUP BY store_id
) t
WHERE t1.store_id = t.store_id;