Data Studio-语法错误:应为输入结尾,但在[68:8]处得到关键字LIMIT



嗨,当我在BigQuery中编写以下查询时,它会执行,但当我试图在Data Studio中添加它时,我得到了以下错误:Data Studio-语法错误:预期输入结束,但在[68:8]处得到了关键字LIMIT

有人能告诉我如何在Data Studio中更正它吗?


if( EXTRACT(month  FROM current_Date) = 9) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2020-08-31'
group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 10) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2020-09-30' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 11) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2020-10-31' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 12) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2020-11-31' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 1) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2020-12-31' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 2) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2021-01-31' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 3) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2021-02-28' group by LCRNEngland order by total );
elseif( EXTRACT(month  FROM current_Date) = 4) then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year` 
where LCRNEngland <> '-' and Study_IsUrgentPublicHealthResearch = false and cast(RecruitmentDate as date) >= '2020-04-01' and cast(RecruitmentDate as date) <= '2021-03-31' group by LCRNEngland order by total );
end if

我找到了一个解决方案。显然谷歌增加了限制条款作为标准。但在添加它之前,会在代码中搜索limit语句。所以你需要在评论中添加,它的工作原理如下:

if
(EXTRACT(month FROM current_Date) = 9)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2020-08-31'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 10)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2020-09-30'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 11)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2020-10-31'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 12)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2020-11-31'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 1)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2020-12-31'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 2)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2021-01-31'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 3)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2021-02-28'
group by LCRNEngland
order by total);
elseif
(EXTRACT(month FROM current_Date) = 4)
then
(SELECT LCRNEngland, sum(RecruitmentCount) as Total
FROM `optical-mind-258908.WM.LCRN_Confirmed_Recruitment_Current_Year`
where LCRNEngland <> '-'
and Study_IsUrgentPublicHealthResearch = false
and cast (RecruitmentDate as date) >= '2020-04-01'
and cast (RecruitmentDate as date) <= '2021-03-31'
group by LCRNEngland
order by total);
end if;
/* LIMIT 100 */

最新更新