Home Database Mysql Tutorial mysql小技巧-不写函数实现split截取_MySQL

mysql小技巧-不写函数实现split截取_MySQL

Jun 01, 2016 pm 01:31 PM
android iphone

bitsCN.com

mysql小技巧-不写函数实现split截取

 

1. 不写函数实现split截取

 

场景:dayNewStat+meilishuo+ipad+2003 (dayNewStat+meilishuo+iphone+2003)(dayNewStat+meilishuo+android+2003) 只取最后一位

 

设想:split('+')[-1]  (python写法)

 

实现:有严格的格式要求,取巧方法,无技术含量

 

1substring(record_tag,locate('+',replace(record_tag,'dayNewStat+meilishuo+',' dayNewStat-meilishuo-')))2. having + min + if
Copy after login

场景:只要status是ok的,且id最小

id      type     status001    aaa      ok002    aaa      error010    aaa      ok003    bbb     ok
Copy after login

实现:去重 & 按条件筛选

1select stat_date,record_tag,substring(record_tag,locate(&#39;+&#39;,replace(record_tag,&#39;dayNewStat+meilishuo+&#39;,&#39; dayNewStat-meilishuo-&#39;))) as client_id,attr_value2from t_stat_daynew_classify_2013063where  record_type=&#39;dayNewStat+app+device+clientID&#39; and record_tag like &#39;dayNewStat+meilishuo+%&#39;  and attr_name =&#39;totalDID&#39; and attr_name_hash = 1380872519 and record_type_hash = 20394970044group by stat_date,record_tag5having min(id) and if( (client_id>10000 and record_tag like &#39;dayNewStat+meilishuo+android%&#39;) or (client_id>2000 and client_id<5000 and record_tag like &#39;dayNewStat+meilishuo+ipad%&#39;)  or (client_id>5000 and client_id<10000),&#39;ok&#39;,&#39;del&#39; ) = &#39;ok&#39; order by stat_date,client_id
Copy after login

 


bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera

Oppo Find X8 design looks like a cross between Apple iPhone 16 Pro and OnePlus Open in early images Oppo Find X8 design looks like a cross between Apple iPhone 16 Pro and OnePlus Open in early images Sep 28, 2024 am 06:04 AM

Oppo Find X8 design looks like a cross between Apple iPhone 16 Pro and OnePlus Open in early images

Gate.io trading platform official app download and installation address Gate.io trading platform official app download and installation address Feb 13, 2025 pm 07:33 PM

Gate.io trading platform official app download and installation address

iQOO Z9 Turbo+ debuts as Dimensity 9300+ smartphone with \'off-the-charts\' battery life iQOO Z9 Turbo+ debuts as Dimensity 9300+ smartphone with \'off-the-charts\' battery life Sep 26, 2024 am 06:20 AM

iQOO Z9 Turbo+ debuts as Dimensity 9300+ smartphone with \'off-the-charts\' battery life

Samsung Galaxy Z Fold Special Edition revealed to land in late October as conflicting name emerges Samsung Galaxy Z Fold Special Edition revealed to land in late October as conflicting name emerges Oct 01, 2024 am 06:21 AM

Samsung Galaxy Z Fold Special Edition revealed to land in late October as conflicting name emerges

How to install and register an app for buying virtual coins? How to install and register an app for buying virtual coins? Feb 21, 2025 pm 06:00 PM

How to install and register an app for buying virtual coins?

Anbi app official download v2.96.2 latest version installation Anbi official Android version Anbi app official download v2.96.2 latest version installation Anbi official Android version Mar 04, 2025 pm 01:06 PM

Anbi app official download v2.96.2 latest version installation Anbi official Android version

Lenovo reveals new color option for the 2024 Legion Y700 gaming tablet Lenovo reveals new color option for the 2024 Legion Y700 gaming tablet Sep 29, 2024 am 06:05 AM

Lenovo reveals new color option for the 2024 Legion Y700 gaming tablet

See all articles