hc学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › gao › 日志

根据教材中的user表和card表进行多表查询

2021-01-07 14:08:21 查看(308) 回复(0)

完成以下功能:


  1. 查询【李峰】的银行卡信息
  2. 查询银行卡号是【001】的客户信息
  3. 查询存款大于10000元的客户姓名和身份证号码
  4. 查询信用积分大于400分的客户姓名和银行存款总额
  5. 查询每个城市的银行存款总额,按存款金额降序排列
  6. 查询在2019年1月1日至2019年3月1日期间,办理新银行卡的客户信息
  7. 查询银行存款大于等于20000元的北京客户信息
  8. 统计男客户、女客户的平均存款金额
  9. 统计每个城市银行卡的数量,要求不包括被冻结的银行卡
  10. 查询每个客户的存款总额
  11. 查询人均存款大于20000的城市名称


-- 查询【李峰】的银行卡信息
select * from card where userID in (select userID from user where name='李峰')
-- 查询银行卡号是【001】的客户信息
select * from user where userID in (select userID from card where cardNo='001')
-- 查询存款大于10000元的客户姓名和身份证号码
select name 客户姓名,personID 身份证号码 from user where userID in (select userID from card where money>10000);
-- 查询信用积分大于400分的客户姓名和银行存款总额
select name,sum(money) from user,card where card.userID=user.userID and credit>400 GROUP BY name 
-- 查询每个城市的银行存款总额,按存款金额降序排列
select city,sum(money) from user,card where user.userID=card.userID GROUP BY city ORDER BY sum(money) desc;
-- --查询在2019年1月1日至2019年3月1日期间,办理新银行卡的客户信息
select user.* from card,user where user.userID=card.userID and openDate BETWEEN '2019-01-01'and '2019-03-01';
-- 查询银行存款大于等于20000元的北京客户信息
select user.* from user,card where user.userID=card.userID and money>='20000' and city='北京';
-- 统计男客户、女客户的平均存款金额
select sex,avg(money)from card,user where user.userID=card.userID GROUP BY sex;
-- 统计每个城市银行卡的数量,要求不包括被冻结的银行卡
select city,count(cardNo) from card,user where user.userID=card.userID and isLock=0 GROUP BY city;
-- 查询每个客户的存款总额
select name,sum(money) from user,card where user.userID=card.userID GROUP BY name 
-- 查询人均存款大于10000的城市名称
select city from user,card where user.userID=card.userID GROUP BY city HAVING avg(money)>'10000';

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.com 备案号:京ICP备14030918号-1

返回顶部