插入 RANK 作为列的值
Inserting RANK as value of a column
我是 sql 的超级新手,不知道是否可行,但是
我想从以下 SELECT DISTINCT 输出中 select RANK 的值并将其插入到名为 Country.table 的第一列。
然后 select address_country 列并将其插入 table“国家/地区”的第二列,但我不知道该怎么做。我真的很感激任何帮助。谢谢!
INSERT INTO Country
SELECT country_code from
(SELECT DISTINCT address_country,
RANK() over (order by address_country asc) AS country_code
FROM CUSTOMER_INFO Where CUSTOMER_INFO.address_country is not NULL),
SELECT address_country from
(SELECT DISTINCT address_country,
RANK() over (order by adr_country asc) AS country_code
FROM CUSTOMER_INFO
Where CUSTOMER_INFO.address_country is not NULL);
如果您想 INSERT INTO ... SELECT
,请使用:
INSERT INTO Country (address_country, country_code)
SELECT address_country, RANK() OVER (ORDER BY adr_country)
FROM CUSTOMER_INFO
WHERE CUSTOMER_INFO.address_country IS NOT NULL;
请注意,计算 RANK
将产生派生数据,或者可能会随着原始 CUSTOMER_INFO
table 的变化而变化的数据。因此,您可能需要重新考虑最初导致您想要执行此插入操作的方法。
我是 sql 的超级新手,不知道是否可行,但是 我想从以下 SELECT DISTINCT 输出中 select RANK 的值并将其插入到名为 Country.table 的第一列。
然后 select address_country 列并将其插入 table“国家/地区”的第二列,但我不知道该怎么做。我真的很感激任何帮助。谢谢!
INSERT INTO Country
SELECT country_code from
(SELECT DISTINCT address_country,
RANK() over (order by address_country asc) AS country_code
FROM CUSTOMER_INFO Where CUSTOMER_INFO.address_country is not NULL),
SELECT address_country from
(SELECT DISTINCT address_country,
RANK() over (order by adr_country asc) AS country_code
FROM CUSTOMER_INFO
Where CUSTOMER_INFO.address_country is not NULL);
如果您想 INSERT INTO ... SELECT
,请使用:
INSERT INTO Country (address_country, country_code)
SELECT address_country, RANK() OVER (ORDER BY adr_country)
FROM CUSTOMER_INFO
WHERE CUSTOMER_INFO.address_country IS NOT NULL;
请注意,计算 RANK
将产生派生数据,或者可能会随着原始 CUSTOMER_INFO
table 的变化而变化的数据。因此,您可能需要重新考虑最初导致您想要执行此插入操作的方法。