简体   繁体   中英

Create new column with 4 values and split existing value from table 4 ways

So I want to create a new column called "Quarters" and then for every line in my existing table create 4 new lines with 1,2,3,4 inserted as the quarters and then divide the field "FPAYG_Quota" by 4 to now make that a quarter quota

SELECT 

1 as Quarter,
FP.ClientOffice,
FP.FPAYG_Quota

FROM `commercial-analysis.2022_AM_Territory.FPAYG_Quotas` as FP 

这是之前和之后

Consider below approach

select ClientOffice, Quarter, FPAYG_Quota / 4 as FPAYG_Quota
from your_table, 
unnest([1,2,3,4]) Quarter

if applied to sample data in your question

with your_table as (
  select 'Client A' ClientOffice, 100 FPAYG_Quota union all 
  select 'Client B', 200
)

output is

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM