当前位置:网站首页>sql语句之字符串截取函数(substring_index)
sql语句之字符串截取函数(substring_index)
2022-08-06 17:01:00 【大数据小王】
一、substring_index:
substring_index(str,delim,count)
- str:要处理的字符串
- delm:分隔符
- count:计数
二、例子
(1)如果count是正数,那么就是从左往右数,第N个分隔符的左边的全部内容
str=www.wikidm.cn
(1) substring_index(str,'.',1)
结果是:www
(2) substring_index(str,'.',2)
结果是:www.wikidm(2) 相反,如果是负数,那么就是从右边开始数,第N个分隔符右边的所有内容,
substring_index(str,'.',-2)
结果为:wikidm.cn
(3)取中间的某个值
从右数第二个分隔符的右边全部,再从左数的第一个分隔符的左边:
substring_index(substring_index(str,'.',-2),'.',1);
结果为:wikidm
二、示例:

1、统计每个性别的用户分别有多少参赛者,请取出相应结果
select
substring_index(profile, ',', -1) as gender,
count(device_id) as number
from user_submit
group by gender

2、把用户的个人博客用户字段提取出单独记录为一个新的字段
select device_id,substring_index(blog_url,'/',-1)
from user_submit

3、统计每个年龄的用户分别有多少参赛者
select substring_index(substring_index(profile,',',-2),',',1) as age,
count(device_id) as number
from user_submit
group by age

边栏推荐
- 资深运营:如何在公众号图文中添加附件,这其实一点都不难
- 好教程推荐系列:收录常见的Qt面试题
- SourceTree使用技巧
- Win7 Ultimate Edition forcibly delete the power-on password Win7 power-on password forgot how to remove
- Windows 7 screen shortcuts is Windows 7 computer screen shortcuts
- 机器学习的命脉:自定义数据集的6个关键步骤,你知道几个?
- 百盛新纪元代理2C快充方案(5)
- win7开机0x0000007b修复不了 win7开机蓝屏0x0000007b
- C专家编程 第7章 对内存的思考 7.7 总线错误
- 【kali-漏洞利用】(3.4)Metasploit渗透攻击应用:MySQL渗透过程
猜你喜欢

windows7激活产品密钥最新免费2022大全(含旗舰版、专业版、家庭版、通用版)

shell之常用小工具(sort、uniq、tr、cut)

How to turn on the wireless screen mirroring function in win7

dedecms proves that the next article on the mobile station has changed to the previous one and there is an error Request Error!

win7无法进入系统和安全模式 win7系统崩溃进不了安全模式

Live-Charts在WPF中的使用

开机f1修复电脑步骤 开机需要按F1才能进入系统

C专家编程 第7章 对内存的思考 7.7 总线错误

Win7 and win10 which takes up less resources Win7 and win10 take up resources in detail

Windows 7 how to set the screen do not close dormant Windows 7 dormancy function
随机推荐
数字化转型要避免“唯技术论”!
win7蓝牙怎么开启 电脑蓝牙在哪里打开win7
基于 OPLG 从 0 到 1 构建统一可观测平台实践
戴尔笔记本键盘灯光怎么开 戴尔电脑键盘灯怎么开
15 tips about SQL optimization
Qt5多线程/线程池技术集锦(2)如何在子线程更新ui窗口
win7旗舰版64位万能激活码 windows7旗舰版激活产品密钥
华硕电脑蓝屏修复按哪个键 电脑一开机就蓝屏反复的解决方法
启牛中信证券下载是可以开户吗?开户安全吗
win7怎么打开无线投屏功能 win7投屏到电视机
C专家编程 第7章 对内存的思考 7.2 Intel 80x86内存模型以及它的工作原理
leetcode-daily question 1408. The difference between string matching in an array (violent enumeration) and the Index method and the Contains method in Golang
王学岗——————H265实现低延时投屏,从零实现高清无损投屏
TCP的三次挥手、四次握手
Integer缓存策略
Ali, phoenix architecture have to pay first book guide to build large-scale distributed systems so precious
sql报错注入
How to format computer to restore factory settings in win7
win7设置每天自动关机 自动关机怎么设置win7
腾讯将取消部分外包免费食堂福利;iPhone 14 Pro或取消远峰蓝,新增紫色;马斯克:我被推特骗了|极客头条...