SELECT
[GMI Division#], [GMI Division],
[Type_Mapping],
SUM(Delv_EQC_Fctr) AS Delv_EQC_Fctr,
SUM(Cuts_EQC_Fctr) AS Cuts_EQC_Fctr
FROM
(SELECT
[GMI Division#], [GMI Division],
[Type_Mapping], [Base Product#],
SUM([BUoM_Delivery Quantity]) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Delv_EQC_Fctr,
(SUM([BUoM_GMI Order Cut Total]) + SUM([BUoM_GMI Delivery Cut Total])) * ([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) AS Cuts_EQC_Fctr
FROM
[dbo].[CF_Weekly_Casefill_Final_TY]
LEFT JOIN
[dbo].[CF_VEDW_PRD_MATL_DIM_N] ON [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#] = CAST([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] AS BIGINT)
GROUP BY
[GMI Division#], [GMI Division], [Type_Mapping], [Base Product#],
[EQC_FCTR], [BUoM_Delivery Quantity], [BUoM_GMI Order Cut Total], [BUoM_GMI Delivery Cut Total])
WHERE
(([GMI Division#] IN (01, 03, 12, 16, 50)
AND [Distribution channel] IN ('RT', 'ML')) OR
([GMI Division#] IN (08) AND [Distribution channel] IN ('FS')))
AND RIGHT([Fiscal Year/Period], 4) IN (2018)
GROUP BY
[GMI Division#], [GMI Division], [Type_Mapping], [EQC_FCTR]
这会在"
附近引发错误"错误的语法答案 0 :(得分:4)
编写代码是第一部分。您需要正确格式化它。没有这种格式化,很难读懂你。
这是您的查询的重写版本
WHERE
我不确定你的char *words[] = { "cherry", "orange", "apple", "oyster"};
条款的问题在哪里。
为了找到问题,我会以这种方式运作。
你有4个条件,它应该很快。
祝你好运
更新
有一个网站,您可以像这样格式化您的代码 - > http://www.sql-format.com/
答案 1 :(得分:1)
你必须给它一个临时名称,如下所示[{1}}:
MyTable
答案 2 :(得分:0)
Select
[GMI Division#]
,[GMI Division]
,[Type_Mapping]
,Sum(Delv_EQC_Fctr) as Delv_EQC_Fctr
,Sum(Cuts_EQC_Fctr) as Cuts_EQC_Fctr
from (
select
[GMI Division#]
,[GMI Division]
,[Type_Mapping]
,[Base Product#]
,Sum([BUoM_Delivery Quantity])
,([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) as Delv_EQC_Fctr
,(Sum([BUoM_GMI Order Cut Total])+Sum([BUoM_GMI Delivery Cut Total]))
,([dbo].[CF_VEDW_PRD_MATL_DIM_N].[EQC_FCTR]) as Cuts_EQC_Fctr
from[dbo].[CF_Weekly_Casefill_Final_TY]
left join [dbo].[CF_VEDW_PRD_MATL_DIM_N]
on [dbo].[CF_Weekly_Casefill_Final_TY].[Base Product#]=cast([dbo].[CF_VEDW_PRD_MATL_DIM_N].[BASPRD_NBR] as bigint)
group by[GMI Division#]
,[GMI Division]
,[Type_Mapping]
,[Base Product#]
,[EQC_FCTR]
,[BUoM_Delivery Quantity]
,[BUoM_GMI Order Cut Total]
,[BUoM_GMI Delivery Cut Total]
) as tbl
where (([GMI Division#] in (01,03,12,16,50)
and [Distribution channel]in ('RT','ML'))
or([GMI Division#] in (08)and [Distribution channel]in ('FS')))
and right([Fiscal Year/Period],4) in (2018)
group by [GMI Division#],[GMI Division],[Type_Mapping],[EQC_FCTR]