SQL31. 提取博客URL中的用户名
描述
device_id | profile | blog_url |
2138 | 180cm,75kg,27,male | http:/ur/bisdgboy777 |
3214 | 165cm,45kg,26,female | http:/url/dkittycc |
6543 | 178cm,65kg,25,male | http:/ur/tigaer |
4321 | 171 cm,55kg,23,female | http:/url/uhksd |
2131 | 168cm,45kg,22,female | http:/url/sydney |
device_id | user_name |
2138 | bisdgboy777 |
3214 | dkittycc |
6543 | tigaer |
4321 | uhsksd |
2131 | sydney |
示例1
输入:
drop table if exists user_submit; CREATE TABLE `user_submit` ( `id` int NOT NULL, `device_id` int NOT NULL, `profile` varchar(100) NOT NULL, `blog_url` varchar(100) NOT NULL ); INSERT INTO user_submit VALUES(1,2138,'180cm,75kg,27,male','http:/url/bisdgboy777'); INSERT INTO user_submit VALUES(1,3214,'165cm,45kg,26,female','http:/url/dkittycc'); INSERT INTO user_submit VALUES(1,6543,'178cm,65kg,25,male','http:/url/tigaer'); INSERT INTO user_submit VALUES(1,4321,'171cm,55kg,23,female','http:/url/uhsksd'); INSERT INTO user_submit VALUES(1,2131,'168cm,45kg,22,female','http:/url/sysdney');
输出:
2138|bisdgboy777 3214|dkittycc 6543|tigaer 4321|uhsksd 2131|sysdney
Mysql 解法, 执行用时: 36ms, 内存消耗: 6384KB, 提交时间: 2021-12-03
select device_id , substring_index(blog_url,'/',-1) as user_name from user_submit
Mysql 解法, 执行用时: 36ms, 内存消耗: 6388KB, 提交时间: 2022-01-27
select device_id,SUBSTRING_INDEX(blog_url,'/',-1) from user_submit #where
Mysql 解法, 执行用时: 36ms, 内存消耗: 6396KB, 提交时间: 2022-01-22
select device_id, replace(blog_url,'http:/url/','') as user_name from user_submit;
Mysql 解法, 执行用时: 36ms, 内存消耗: 6408KB, 提交时间: 2021-12-06
select device_id,SUBSTRING_INDEX(blog_url,'url/','-1') as user_name FROM user_submit
Mysql 解法, 执行用时: 36ms, 内存消耗: 6420KB, 提交时间: 2021-12-27
SELECT device_id,REPLACE(blog_url,'http:/url/','')user_name FROM user_submit