我在表格中插入一列时遇到问题。我已经计算了其中一列的分位数,但是如何插入表中呢?

.open books.db

ALTER TABLE booksCSV ADD COLUMN quantile_rank;

SELECT average_rating, NTILE(4) OVER (ORDER BY average_rating DESC) AS quantile_rank FROM booksCSV;

最佳答案

添加列之后,可以按如下方式使用CTE:

WITH cte as (SELECT rowid, NTILE(4) OVER (ORDER BY average_rating DESC) AS qr FROM booksCSV)
UPDATE booksCSV
SET quantile_rank = (SELECT qr FROM cte
                     WHERE booksCSV.rowid = rowid);

关于sql - 如何根据另一列的分位数将新列插入标签为“1”/“2”/“3”/“4”#的数据库中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58758758/

10-11 17:58