0

这是我的查询:

 SELECT 
 a.account_type AS ACCOUNT_TYPE
,b.at_account_type_desc
,COUNT(a.BAN) AS num_BAN 
 FROM csm_adx.billing_account_act AS a 
 LEFT OUTER JOIN csm_adx.account_type_act AS b ON a.account_type = b.at_acc_type
 GROUP BY 1,2

现在我想将它连接到另一个表 TABLE_C,其中包含的信息是帐户:暂定、取消、关闭、暂停、打开。

我希望我的结果表包含另外三列:ACTIVE_BANSUSPENDED_BAN并且CANCELLED_BAN 每个值都包含当前活动、暂停和取消禁令的数量。我正在使用 Teradata。

你能帮我做这件事吗?

这是当表与另一个包含 BAN 状态的表连接时的结果:

SELECT 
 a.account_type AS ACCOUNT_TYPE
,b.at_account_type_desc
,c.description
,COUNT(a.BAN) AS num_BAN
FROM csm_adx.billing_account_act AS a
LEFT OUTER JOIN csm_adx.account_type_act AS b 
ON a.account_type = b.at_acc_type
LEFT OUTER JOIN csm_adx.acct_status AS c
ON a.ban_status = c.original_status_code
GROUP BY 1,2,3
4

1 回答 1

1
SELECT 
 a.account_type AS ACCOUNT_TYPE
,b.at_account_type_desc
,COUNT(a.BAN) AS num_BAN ,
 sum(case when a.column=value then 1 else 0 end) as 'user_colname1',
sum(case when b.column=value then 1 else 0 end) as 'user_colname2'
 FROM csm_adx.billing_account_act AS a 
 LEFT OUTER JOIN csm_adx.account_type_act AS b 
ON a.account_type = b.at_acc_type
 GROUP BY 1,2
于 2012-09-19T09:09:41.713 回答