有sql脚本如下:use kdd99; create table kdd99_accounts ( account_id integer, district_id integer, frequency varchar(20), date DATE ); load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/kdd99_accounts.csv' into table kdd99_accounts CHARACTER SET gb2312 fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n'; create table Kdd99_card( card_id integer, disp_id integer, issued DATE, type varchar(10) ); load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Kdd99_card.csv' into table Kdd99_card CHARACTER SET gb2312 fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n'; create table Kdd99_disp( disp_id integer, client_id integer, account_id integer, type varchar(6) ); load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Kdd99_disp.csv' into table Kdd99_disp CHARACTER SET gb2312 fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n'; create table Kdd99_trans( trans_id integer,account_id integer,date date,type varchar(2),operation varchar(20),amount long,balance long,k_symbol varchar(20),bank varchar(4),account long ); load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Kdd99_trans.csv' into table Kdd99_trans CHARACTER SET gb2312 fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';请问如何验证客户开通信用卡之后,其账户余额相较于开卡之前是否有提升
时间: 2023-12-08 22:06:44 浏览: 63
可以通过以下SQL语句来验证客户开通信用卡之后,其账户余额是否有提升:
```
SELECT
kdd99_accounts.account_id,
kdd99_accounts.frequency,
SUM(CASE WHEN Kdd99_trans.type = 'PRIJEM' THEN Kdd99_trans.amount ELSE 0 END) - SUM(CASE WHEN Kdd99_trans.type = 'VYDAJ' THEN Kdd99_trans.amount ELSE 0 END) AS balance_before_card,
SUM(CASE WHEN Kdd99_trans.type = 'PRIJEM' AND Kdd99_trans.trans_id > (SELECT MIN(Kdd99_trans.trans_id) FROM Kdd99_trans WHERE Kdd99_trans.account_id = kdd99_accounts.account_id AND Kdd99_trans.type = 'VYBER' AND Kdd99_trans.date > Kdd99_card.issued) THEN Kdd99_trans.amount ELSE 0 END) - SUM(CASE WHEN Kdd99_trans.type = 'VYDAJ' AND Kdd99_trans.trans_id > (SELECT MIN(Kdd99_trans.trans_id) FROM Kdd99_trans WHERE Kdd99_trans.account_id = kdd99_accounts.account_id AND Kdd99_trans.type = 'VYBER' AND Kdd99_trans.date > Kdd99_card.issued) THEN Kdd99_trans.amount ELSE 0 END) AS balance_after_card
FROM
Kdd99_disp
JOIN Kdd99_card ON Kdd99_disp.disp_id = Kdd99_card.disp_id
JOIN kdd99_accounts ON Kdd99_disp.account_id = kdd99_accounts.account_id
LEFT JOIN Kdd99_trans ON Kdd99_trans.account_id = kdd99_accounts.account_id
WHERE
Kdd99_card.type = 'VISA'
GROUP BY
kdd99_accounts.account_id,
kdd99_accounts.frequency
HAVING
balance_after_card > balance_before_card;
```
该SQL语句会查询出所有开通了VISA信用卡的客户账户,并计算出开卡之前和开卡之后的账户余额,然后筛选出开卡之后账户余额比开卡之前高的客户账户。如果有结果,则说明客户开通信用卡之后其账户余额有提升。
阅读全文