现有3张银行数据表,求数据表中账户办理的新卡开卡前账户余额
KDD99_CARD,每条记录描述了一个账户上的信用卡信息
信用卡(Cards)表
名称 标签card_id 信用卡id(主键)disp_id 账户权限号type 卡类型issued 发卡日期KDD99_DISP,每条记录描述了客户和账户之间的关系,以及客户操作账户的权限
权限分配表(Disp)
名称 标签 说明disp_id 权限设置号 (主键)client_id 顾客号account_id 账户号type 权限类型 只用”所有者” 身份可以进 行进行增值 业务操作和 贷款KDD99_TRANS,每条记录代表每个账户上的一条交易
交易表 (Trans)
名称 标签trans_id 交易序号(主键)account_id 发起交易的账户号date 交易日期type 借贷类型operation 交易类型amount 金额balance 账户余额K_Symbol 交易特征bank 对方银行account 对方账户号思路:三表左连接后输出目标
SQL:
PROC SQL; CREATE TABLE WORK.QUERY_FOR_KDD99_CARD_0001(label="QUERY_FOR_KDD99_CARD") AS SELECT t1.card_id, t1.disp_id, t1.issued, t1.type, /* MAX_of_date */ (MAX(t3.date)) FORMAT=YYMMDD10. AS MAX_of_date, t3.account_id FROM CDA1.KDD99_CARD t1 LEFT JOIN CDA1.KDD99_DISP t2 ON (t1.disp_id = t2.disp_id) LEFT JOIN CDA1.KDD99_TRANS t3 ON (t2.account_id = t3.account_id) WHERE t2.type = '所有者' AND t1.issued > t3.date GROUP BY t1.card_id, t1.disp_id, t1.issued, t1.type, t3.account_id;QUIT;
PROC SQL; CREATE TABLE WORK.QUERY_FOR_KDD99_CARD_0002(label="QUERY_FOR_KDD99_CARD") AS SELECT t1.card_id, t1.disp_id, t1.issued, t1.type, t1.MAX_of_date, t1.account_id, /* MEAN_of_balance */ (MEAN(t2.balance)) FORMAT=DOLLAR. AS MEAN_of_balance FROM WORK.QUERY_FOR_KDD99_CARD_0001 t1 LEFT JOIN CDA1.KDD99_TRANS t2 ON (t1.account_id = t2.account_id) AND (t1.MAX_of_date = t2.date) GROUP BY t1.card_id, t1.disp_id, t1.issued, t1.type, t1.MAX_of_date, t1.account_id;QUIT;
先放这后期再编辑