select b_c_id, b_balance, b_type into s_id, s_b, s_type from bank_card where b_number = source_card_id;
时间: 2024-04-23 09:26:35 浏览: 64
这是一个 MySQL 查询语句,用于从 bank_card 表中根据银行卡号查询出该银行卡的持有人 ID、余额和类型,并将结果赋值给变量 s_id、s_b 和 s_type。该查询使用了 SELECT INTO 语句,可以将查询结果直接赋值给变量。其中,b_number 是 bank_card 表中的一个字段,用于保存银行卡号;b_c_id、b_balance 和 b_type 分别是 bank_card 表中的字段,用于保存银行卡的持有人 ID、余额和类型。
相关问题
BEGIN declare s_id, r_id int; declare s_type, r_type char(20); declare s_b, rcv_amount numeric(10, 2) default amount; select b_c_id, b_balance, b_type into s_id, s_b, s_type from bank_card where b_number = source_card_id; select b_c_id, b_type into r_id, r_type from bank_card where b_number = dest_card_id;这段什么意思
这段代码是一个存储过程的开头。存储过程用于执行一系列预定义的SQL语句。这个存储过程中首先声明了一些变量,包括s_id, r_id, s_type, r_type, s_b和rcv_amount。然后,通过查询bank_card表来获取source_card_id和dest_card_id对应的银行卡的信息。select语句将b_c_id, b_balance和b_type的值分别赋给s_id, s_b和s_type。接着,又通过查询获取了dest_card_id对应的银行卡的b_c_id和b_type,并分别赋值给r_id和r_type变量。这段代码的作用是从bank_card表中获取相关银行卡的信息,以备后续的操作使用。
有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';请问如何验证客户开通信用卡之后,其账户余额相较于开卡之前是否有提升
要验证客户开通信用卡之后,其账户余额相较于开卡之前是否有提升,可以根据以下步骤进行:
1. 对于每个客户,找到其开卡的日期(可以从 Kdd99_card 表中获取)和账户余额(可以从 Kdd99_accounts 表中获取)。
2. 找到客户所有的交易记录(可以从 Kdd99_trans 表中获取),筛选出交易类型为 "PRIJEM"(即存款)的记录,且操作描述为 "VKLAD"(即存入)的记录。这些记录表示客户向其账户中存入的金额。
3. 对于每个客户,计算其开卡后存入账户的总金额,即在开卡日期之后的所有符合条件的交易记录中,amount 字段的总和。
4. 将开卡前的账户余额和开卡后存入账户的总金额相加,得到客户开卡后的总账户余额。
5. 比较客户开卡后的总账户余额和开卡前的账户余额,如果前者大于后者,则说明客户开通信用卡后其账户余额有提升。
可以通过如下 SQL 语句实现以上步骤:
```
SELECT
kdd99_card.disp_id,
kdd99_card.issued AS card_issued_date,
kdd99_accounts.balance AS pre_card_balance,
SUM(CASE WHEN kdd99_trans.operation = 'VKLAD' AND kdd99_trans.type = 'PRIJEM'
THEN kdd99_trans.amount ELSE 0 END) AS post_card_deposit,
kdd99_accounts.balance + SUM(CASE WHEN kdd99_trans.operation = 'VKLAD' AND kdd99_trans.type = 'PRIJEM'
THEN kdd99_trans.amount ELSE 0 END) AS post_card_balance
FROM
kdd99_card
INNER JOIN kdd99_disp ON kdd99_card.disp_id = kdd99_disp.disp_id
INNER JOIN kdd99_accounts ON kdd99_disp.account_id = kdd99_accounts.account_id
LEFT JOIN kdd99_trans ON kdd99_accounts.account_id = kdd99_trans.account_id
AND kdd99_trans.date > kdd99_card.issued
GROUP BY
kdd99_card.disp_id, kdd99_card.issued, kdd99_accounts.balance
HAVING
post_card_balance > pre_card_balance;
```
该 SQL 语句将返回所有开通信用卡后账户余额有提升的客户的 disp_id(即客户表中的唯一标识)、信用卡开卡日期、开卡前账户余额、开卡后存入账户的总金额和开卡后总账户余额。
阅读全文