1
현재 BigQuery에서 사용하기 위해 이전 T-SQL 스크립트 중 일부를 변환 중입니다. 문제가 있습니다. SELECT에 사용 된 모든 집계되지 않은 필드에 대해서도 CASE WHEN의 일부로 GROUP BY에 선언해야합니다. 이것은 T-SQL에서 문제가되지 않는 것처럼 보입니다. 어쨌든이 문제는 처음 세 필드에서만 그룹화해야합니까?그룹화 기준 Google BigQuery
즉없이 :
ss.UK_Sample_Size,
ss.Study_Design_Type
코드가 첨부 : 사전에
SELECT
LCRN AS [OrganisationName],
os.populationinmillions as [population_in_millions],
os.percentageoftotalpopulation as [percentage_of_total_population],
SUM([recruitmentcount]) as recruitment,
SUM(CASE WHEN ss.UK_Sample_Size >=10000 then sum(recruitmentcount) end) as Band1_Recruitment,
SUM(CASE WHEN (ss.Study_Design_Type = 'Observational' or ss.Study_Design_Type = 'Not Specified') and (ss.UK_Sample_Size < 10000 or ss.UK_Sample_Size is null) then sum(recruitmentcount) end) as Observational_Recruitment,
SUM(CASE WHEN (ss.Study_Design_Type = 'Interventional' or ss.Study_Design_Type = 'Both') and (ss.UK_Sample_Size < 10000 or ss.UK_Sample_Size is null) then sum(recruitmentcount) end) as Interventional_Recruitment
// PROBLEM
// 1. We dont want to group on study design type and uk sample size
// 2. We want to select by a date value held as a variable
FROM
[mydataset.BQ_Upload_ALL] AS bq
JOIN
[mydataset.Study_Summary] AS ss
ON
bq.studyid = ss.study_id
JOIN
[mydataset.ONS_Population] as os
ON
bq.LCRN = os.LocalNetwork
WHERE
recruitmentactivitydate_fy = '2016/17'
GROUP BY
[OrganisationName],
[population_in_millions],
[percentage_of_total_population],
ss.UK_Sample_Size,
ss.Study_Design_Type
ORDER BY
recruitment DESC;
감사합니다,
데이브