1
私は現在、BigQueryで使用するために古いT-SQLスクリプトの一部を変換していますが、問題はあります。SELECTで使用された非集約フィールドCASE WHENの一環として、GROUP BYで宣言しなければなりません - 私は望みません!これはT-SQLの問題ではないようですが、これの周りには最初の3つのフィールドだけをグループ化する必要がありますか?グループby by 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;
おかげで、
デイブを