我一直在与Teradata合作,从数据库中提取一些信息。我很熟悉我遇到的错误,其中包括我所选择的其中一个'选择'变量。
然而,我回去检查了,应该把所有的计数都弄好了。 我认为这与我最后几个和函数有关,因为它们引用了另一个表格'我创造了。可能需要作为一个int或什么东西?
我无法查询主表的原因是我的主表,当我试图做同样的事情时,运行大约4.3M行。
select
isitable.PA_ID
,isitable.A_NM
,isitable.ISI_IND
,isitable.CAMP_ID
,sum(isitable.rewardAmount) as Reward_Amount
,sum(isitable.WP) as WP
,isitable.TM
,isitable.RM
,isitable.LOB
,isitable.Region
,isitable.OM_ID
,isitable.OM_NM
,isitable.BM_ID
,isitable.BM_NM
,isitable.State
,extract(month from isitable.QI_DATE) as QI_Month
,extract(year from isitable.QI_DATE) as QI_Year
,sum(isitable.ISI_Q) as ISI_Q
,sum(isitable.ISI_I) as ISI_I
,sum(isitable.Q) as Q
,sum(isitable.I) as I
from
(
SELECT
dim.GUID
,dim2.PA_ID
,dim2.A_NM
,ISI.CAMP_ID
,isi.rewardAmount
,
case when fact.I = 1 then fact.QPA
else 0
end as WP
,dim2.TM
,dim2.RM
,dim.LOB
,dim2.Region
,dim2.OM_ID
,dim2.OM_NM
,dim2.BM_ID
,dim2.BM_NM
,dim2.State
,fact.Q
,fact.I
,fact.D
,fact.QI_Date
,
case when dim.GUID = ISI.GUID then 'Y'
else 'N'
end as ISI_Ind
,
case when isi_ind = 'Y' then sum(fact.q_cnt)
else 0
end as ISI_Q
,
case when isi_ind = 'Y' then sum(fact.i_cnt)
else 0
end as ISI_I
,
case when isi_ind = 'N' then sum(fact.q_cnt)
else 0
end as Q
,
case when isi_ind = 'N' then sum(fact.i_cnt)
else 0
end as I
FROM facttable AS fact
JOIN dimtable AS dim
ON fact.App_ID = dim.App_ID
JOIN dimtable1 AS dim1
ON fact.Dist_D = dim1.Dist_ID
JOIN dimtable2 AS dim2
ON dim1.A_ID = dim2.A_ID
LEFT JOIN isitable as isi
ON dim.GUID = ISI.GUID
left join isiusertable as isiuser
on isi.userid = isiuser.userid
where QI_Date >= '2017-01-01'
Group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) as isitable
where isitable.Camp_ID is null
or isitable.Camp_ID in ('324', '325', '326', '327', '320', '323',
'317', '319', '318', '313', '315', '316', '314', '301', '302',
'298', '300', '299', '295', '297', '294', '296', '292', '293',
'290', '287', '289', '288', '276', '277', '273', '274', '272',
'269', '266', '263', '260', '258','244', '241','237', '236',
'61')
group by 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17
order by 1,2,3,4,7,8,9,10,11,12,13,14,15,16,17
对于任何连接错误道歉,我必须尽可能地审查表名和联接。