还剩2页未读,继续阅读
文本内容:
提示不要把答案先发给学生,实验结束后再公布答案要让学生先自己思考做题,老师对学生不会的题目适当提示,一题题解决困惑实验连接查询参考代码5继续使用实验创建的银行储蓄数据库,客户信息表、账户信息2customerinfo accountinfo表、交易信息表三个表的表结构见表表transInfo2-18〜2-20查询所有客户的账户信息,包括客户编号、客户姓名、电话、账号、存款类型、货币类1型、开户时间、账户余额、账户状态--说明先写三个“select*from表名”语句查看三张表中有哪些信息select*from customerinfoselect:from accountinfoselect from transInfo-确定要查询的数据取自哪个表,确定表之间关联通过同名列值相等关联-将所有表名写在FROM后面,关联条件写在where后面-注意只在一个表中存在的列名直接写,多个表中同名的列要写“表名.列名”select accountinfo.customerlD,customerName,phone,accountID,savingType,money Typefrom customerinfo,accountinfo一本题只需两张表where customerinfo.customerlD=accountinfo.customerlD--关联条件-查询结果行数与accountinfo表中数据行数一致U口结果消息customerlD customerName phone accountIDsavingType moneyType1[21同学12211111002活期人民币23同学23311111003活期港币34张亮亮4311111004活期人民币45亮晶晶5511111005活期人民币56张华6611111006活期人民币67李莉华7711111007活期人民币72同学12211111008活期人民币同学8323311111009活期人民币92同学12211111010活期人民币同学活期人民币10323311111011111你的名字1111112001活期人民币查询已…行©LAPTOP-NMGPMIMM\sql
200810...LAPTOP-NMGPMIMM\wyiqin...bank00:00:0011查询所有交易信息,包括客户姓名、电话、账号、交易类型、交易金额、交易时间并2按照客户姓名、交易时间排序--说明先写“select*表名”语句查看交易信息表哪些信息select from transInfo-交易类型、交易金额、交易时间在交易信息表中,其他信息在另外两张表中select*from customerinfoselect:from accountinfo-将所有表名写在FROM后面,关联条件写在where后面同名列值相等关联-只在一个表中存在的列名直接写,多个表中的同名列要写”表名.列名”-为缩短代码,可以给三个表分别起别名c,a,tselect customerName,phone,a.accountID,transType,transMoney,transDate fromcustomerinfoc,accountinfo a,transInfo t一三张表需两个关联条件where c.customerlD=a.customerlD anda.accountID=t.accountIDorder bycustomerName,transDate-按照客户姓名、交易时间排序--查询结果行数与transInfo表中数据行数一致S结果th消息customerNamephone accountID transTypetransMoney transDate;李莉华7711111007存入
600.002023-05-0600:00:00,0001一日日冗日日日日25511111005存入
40.002023-05-0600:00:
00.000你的名字存入
31111112001500.002023-05-0600:00:
00.000你的名字存入2023-06-1222:03:
41.
8674111111200110.00你的名字存入2023-06-1222:03:
41.
867511111120012000.00你的名字支取2023-06-1222:03:
41.
8676111111200120.00你的名字存入2023-06-1222:03:
41.
86771111112001100.00同学存入
812211111002300.002023-05-0600:00:
00.000同学存入
9122111110081000.002023-05-0600:00:
00.000同学存入
10122111110101200.002023-06-1222:03:
41.867同学支取
1112211111002100.002023-06-1222:03:
41.867同学存入
12233111110091100.002023-05-0600:00:
00.0000季旬已飒执行.I LAPTOP-NMGPMIMM\sql
200810...LAPTOP-NMGPMIMM\wyiqin...bank00:00:0016行查询所有“芜湖”客户的客户编号、客户姓名、电话、账号、存款类型、账户余额、3账户状态,按照姓名排序提示在客户信息表中修改数据,制造数据验证查询效果--说明先写三个,select*fh m表名”语句查看三张表中有哪些信息select fromcustomerinfoselect*from accountinfoselect*from transInfo--确定从哪些表查询哪些数据,按同名列关联相关表,n张表需nJ个关联条件accountMoney,accountstatefrom customerinfoc,accountinfo a-本题只需两张表where c.customerlD=a.customerlD-两张表需要写一个关联条件and addresslike%芜湖%,-对地址模糊查询,加入“芜湖”的条件order bycustomerName-按照姓名排序select c.customerlD,customerName,phone,a.accountID,savingType,□结果匕消息customerlD customerNamephoneaccountIDsavingType accountMoneyaccountstate11|你的名字1111112001活期259000正常24张亮亮4311111004活期
30.00正常查询已成功执行.©行LAPTOP-NMGPMIMM\sql
200810...LAPTOP-NMGPMIMM\wyiqin...bank00:00:002查询你的某一位好友在本银行的账户信息,包括客户姓名、电话、账号、存款类型、账4户余额按姓名查询一说明本题需客户信息customerinfo表、账户信息accountinfo表两张表selectcustomerName,phone,a.accountID,savingType,accountMoneyfrom customerinfoc,accountinfo awhere--两个表名写在FROM后面c.customerlD=a.customerlD and-两张表需要一个关联条件好友名customerName=’-好友的名字自己定查询账户余额在到之间的账户的信息,包括客户姓名、账号、账户余额5100300-说明依旧只涉及两张表,只是查询条件不同select customerName,a.accountID,accountMoneyfrom customerinfoc,accountinfo a一本题只需两张表where c.customerlD=a.customerlD一两张表需要一个关联条件and accountMoneybetween100and300--也可以不用between...andselect customerName,a.accountID,accountMoneyfrom customerinfoc,accountinfo awhere c.customerlD=a.customerlDand accountMoney=100and accountMoney=300查询账户余额最高的前十个账户的客户编号、客户姓名、电话、账号、账户余额6-说明前n个用top n语句,本题涉及两张表select top10customerName,phone,a.accountID,accountMoneyfrom customerinfoc,accountinfo a一本题只需两张表wherec.customerlD=a.customerlD一两张表需一个关联条件order byaccountMoney desc-按余额降序排序才能取最高的查询单笔存款金额大于元的客户信息,显示客户姓名、电话、账号、存款金额提7500示在交易信息表中修改原有数据的存款金额,制造数据验证查询效果-说明先写三个“select*什om表名”语句查看三张表中有哪些信息selectfrom customerinfoselect:from accountinfoselect*from transInfo-本题需要从三个表取数据,所需表按同名列关联select customerName,phone,a.accountID,transType,transMoneyfrom customerinfoc,accountinfo a,transInfo twherec.customerlD二a,customerlD anda.accountID二t.accountIDand transMoney500and transType廿存入,一存款金额大于500的查询客户的银行卡情况,显示客户姓名、银行卡数量、账户总余额,并给出汉字列名8-说明本题需要从两个表取数据,所需表按同名列关联select*from customerinfoselect:from accountinfo--按客户姓名分组,用count函数统计银行卡数量,sum函数统计账户总余额select customerName客户姓名,COUNT*银行卡数量,SUMaccountMoney账户总余额from customerinfo,accountinfowhere customerinfo.customerTD=accountlnfo.customerlD一表名.歹山名group bycustomerName--按客户姓名分组查询存、取款次数超过两次的账户信息,显示账号、货币类型、存取款次数9-说明在交易信息表中查询存取款次数,在账户信息表中查询货币类型-所以本题需要从两个表取数据,所需表按同名列关联select:from accountinfoselectfrom transInfo-本题需要按账号、货币类型分组,用having子句筛选超过两次的select a.accountID账号,moneyType货币类型,COUNT*存取款次数from accountinfo a,transInfo t--两张表分别起别名,where a.accountID=t.accountID一不能写表名.列名,应该写别名.列名group bya.accountID,moneyType—select后面除聚合函数之外的所有列having COUNT*2--筛选超过两次的查询存、取款次数超过两次的客户信息,显示客户姓名、账号、存取款次数,并按姓10名升序,同一客户的多个账号按次数降序排列―说明客户姓名在客户信息表中在交易信息表中查询存取款次数,在账户信息表中查询货币类型-所以本题需要从三个表取数据,所需表按同名列关联select:fromcustomerinfoselect::from accountinfoselectfromtransInfo-本题需要按客户姓名、账号分组,用having子句筛选超过两次的select customerName客户姓名,a.accountID账号,COUNT*存取款次数fromcustomerinfoc,accountinfoa,transInfo t一三张表分另起另ll名where a.accountID=t.accountID andc.customerlD=a.customerlDgroup bycustomerName,a.accountID-select后面除聚合函数之外的所有列having COUNT*〉2-筛选超过两次的order bycustomerName,COUNT*desc--先姓名升序,后次数降序。
个人认证
优秀文档
获得点赞 0