关于本站
人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!
经管之家新媒体交易平台
提供"微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯"等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】
期刊
- 期刊库 | 马上cssci就要更新 ...
- 期刊库 | 【独家发布】《财 ...
- 期刊库 | 【独家发布】“我 ...
- 期刊库 | 【独家发布】“我 ...
- 期刊库 | 【独家发布】国家 ...
- 期刊库 | 请问Management S ...
- 期刊库 | 英文期刊库
- 核心期刊 | 歧路彷徨:核心期 ...
TOP热门关键词
扫码加入数据分析学习群 |
sql查询语句相关问题
有一个计费表 表名 jifei字段如下: phone(8位的电话号码), month(月份),expenses(月消费,费用为0表明该月没有产生费用)
下面是该表的一条记录:64262631,201011,30.6这条记录的含义就是64262631的号码在2010年11月份产生了30.6元的话费。
按照要求写出满足下列条件的sql语句:
1、查找2010年6、7、8月有话费产生但9、10月没有使用并(6、7、8月话费均在51-100元之间的用户。
select distinctphone from jifei
where month='201006'and
expenses between 51and 100
and phone in (
select distinctphone from jifei
where month='201007'
and expenses between51 and 100)
and phone in (
select distinctphone from jifei
where month='201008'
and expenses between51 and 100)
and phone in (
select distinctphone from jifei
where month='201009'
and expenses =0)
and phone in (
select distinctphone from jifei
where month='201010'
and expenses =0)
;
2、查找2010年以来(截止到10月31日)所有后四位尾数符合AABB或者ABAB或者AAAA的电话号码。(A、 B 分别代表1—9中任意的一个数字)
select distinctphone from jifei
whereto_date(month,'yyyymm')<=to_date('201010 ','yyyymm')
and(substr(phone,5,1)=substr(phone,6,1)
andsubstr(phone,7,1)=substr(phone,8,1))
or(substr(phone,5,1)=substr(phone,7,1)
andsubstr(phone,6,1)=substr(phone,8,1))
or(substr(phone,5,1)=substr(phone,6,1)
andsubstr(phone,5,1)=substr(phone,7,1)
andsubstr(phone,5,1)=substr(phone,8,1)
andsubstr(phone,5,1)=substr(phone,9,1))
;
3、删除jifei表中所有10月份出现的两条相同记录中的其中一条记录。
方法:添加一列ID,作为主键
delete from jifei a
wheresubstr(a.month,5,2)='10'
and(a.phone,a.month) in
(select phone,monthfrom jifei
group by phone,month
havingcount(*)>1)
and a.id not in (
select min(id) fromjifei
group by phone,month
havingcount(*)>1) ;
4、查询所有9月份、10月份月均使用金额在30元以上的用户号码(结果不能出现重复)
select phone from (
selectphone,avg(expenses) as avg_exp from(
select distinct *from jifei
wheresubstr(month,5,2) in ('09','10'))
group by phone)
whereavg_exp>=30;
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
您可能感兴趣的文章
本站推荐的文章
人气文章
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。