Home Database Mysql Tutorial 一个对字符串处理的SQL_MySQL

一个对字符串处理的SQL_MySQL

Jun 01, 2016 pm 01:28 PM
string

bitsCN.com

一个对字符串处理的SQL

 

某表中有一个json格式的字段 如props里有以下字符 

 

1

{"1":36,"2":54,"3":160,"4":8,"5":767680,"6":12,"7":1,"8":8, "13":"14,17,21,20,23,22,25,24,29,28,31,30,34,35,32,33,39,96,42,43,108,40,41,107,44,116,115,114,112,125,124","14":{"15":"0","13":"3","14":"0","11":"3","12":"3","3":"56","2":"38","1":"56","10":"4","7":"40","6":"55","5":"57","4":"37", "9":"6","8":"13"},"15":[{"8":[-1,288516249174946623,-1,288516249174945177,288516249174978057,288516249174977954,-1,288516249174938096,-1,7,0]},{"9":[0,-1,-1,288516249174938096,288516249174946623,-1,-1,-1,0,3,-1]},{"11":[-1,288516249174938096,0,-1,-1,0,-1,-1,-1,1,-1]}, {"10":[-1,288516249174938096,-1,-1,0,-1,-1,0,-1,1,-1]},{"12":[-1,288516249174938096,-1,0,-1,0,-1,-1,-1,1,-1]}, {"13":[288516249174938096,-1,0,-1,-1,-1,-1,-1,0,0,-1]}],"16":160,"18":{"0":1381766801601,"1":1381823994910}, "19":8,"20":767671,"21":[1030990,2,-1,2,0,3,0,4,0,5,0,6,0,3,0,0], "22":{"9012":"1001,1381762836328,1,1,0,false,[false;0;0]","9011":"1001,1381707248623,1,1,0,false, [false;0;0]","2021":"1001,1379343644952,1,1,0,false, [false;0;0]","2020":"1001,1379317060249,1,1,0,false,[false;0;0]","9010":"1001,1381634617324,1,1,0,false, [false;0;0]","2022":"1001,1379469893656,1,1,0,false,[false;0;0]","1008":"1001,1379516486264,1,1,0,false, [false;0;0]","1111":"1001,1380020062745,1,1,0,false,[false;0;0]","1010":"1001,1379765171241,1,1,0,false, [false;0;0]","1011":"1001,1379853879986,1,1,0,false,[false;0;0]","9000":"1001,1381543622820,1,1,0,false,[false;0;0]"}, "23":{"3":"[288516249174954963,288516249174942369,288516249174955163,288516249174954795,288516249174947676]","1":"1"},"24":{"0":1030990,"1":2,"2":0,"3":0},"25":[180,35,3,0,1,8,5,4,4,3,10],"26":402,"27":{"0":1381782823890,"1":[]}, "28":{"2":[49,37,25,18,2,1],"1":4,"0":1381767129747},"29":15,"30":8,"31":"","32":"","33":0,"34":[10020,1], "35":1,"36":[0,0,1030977,""],"37":0,"38":0,"39":[[288516249174945651,288516249174942150,288516249174942809, 288516249174954842,288516249174953399,288516249174944948,288516249174946420,288516249174953771,288516249174950819,288516249174943615]],"40":[],"41":0,"42":0,"43":0,"44":0,"45":0,"46":[22,1,1,0,[[1,7,0,[[[1,1381795409928,false,true,3], 81063479]]],[2,7,0,[[[5,1381763877328,false,true,1],3072]]],[4,4,1,[[[3,1381767432593,false,true,1],0]]],[5,7,0,[[[2,1381 795422562,false,false,2],994861454]]]],[5]],"47":[10,0,true],"48":0,"49":[-1,0,0,0],"50":0,"51":[] "52":[16,2,0],"53":7,"54":2,"55":[],"56":50400,"57":0,"58":"","60":[0],"61":[68,69,70,71],"62":{"throwSeq":1},"63":[],"64":{"1":{}, "2":{}},"65":[],"66":[0],"67":{"1":[],"3":0,"4":0,"5":0,"2":[]},"68":0,"69":50,"70":1381762800263,"71":[[],50,1381821984680]}

Copy after login

现在要查出第56个属性的值

即有如何 SQL:

1

select passportId,level, cast(substring(props,position(&#39;,"56":&#39; in props)+6,position(&#39;,"57":&#39; in props)-position(&#39;,"56":&#39; in props)-6) as signed integer) as num,cast(substring(props,position(&#39;,"56":&#39; in props)+6,position(&#39;,"57":&#39; in props)-position(&#39;,"56":&#39; in props)-6) as signed integer)/1200 h_count from t_character_info where  cast(substring(props,position(&#39;,"56":&#39; in props)+6,position(&#39;,"57":&#39; in props)-position(&#39;,"56":&#39; in props)-6) as signed integer) >0; 如果在shell中分布试查出各个数据库的内容 并把内容邮件形式发出: 即把以上sql 存入到sql文件里 程序如下: #! /bin/sh last_date=$(date -d last-day +%Y_%m_%d); cat /dev/null > $last_date.data for s_ip in $(awk -F= &#39;{print $0}&#39; /root/action_shell/kr_ip.txt); do         echo ===============================start to do task===================================================;         s=$(echo $s_ip|awk -F= &#39;{print $1}&#39;);         ip=$(echo $s_ip|awk -F= &#39;{print $2}&#39;);         echo &#39;=====================&#39;$s&#39;.cqkr.huayugame.com==============================================&#39; >>/root/action_shell/$last_date.data         out1=$(mysql -h$ip -uxxx -pxxx -Dgen -e &#39;source query_hounter.sql&#39; >> /root/action_shell/$last_date.data);        echo $out1;         sleep 10         echo ===============================send mail successfully===================================================; done /bin/mail -s &#39;from games.asia team tech &#39;_$last_date  mingming.wang@renren-inc.com   games.asia< /root/action_shell/$last_date.data 运行效果如下: =====================s1.cqkr.huayugame.com=============================== passportId level num h_count 102833976 78 2400 2.0000 102835789 84 4800 4.0000 102837173 72 12000 10.0000 102837399 72 51600 43.0000 102837452 74 3600 3.0000 102839736 56 48000 40.0000 102775934 60 50400 42.0000 =====================s2.cqkr.huayugame.com================================== passportId level num h_count 102928945 76 2400 2.0000 102966633 63 72000 60.0000 102968267 64 12000 10.0000 102923416 67 1200 1.0000 102970589 57 48000 40.0000 102971607 68 28800 24.0000 102885000 69 12000 10.0000 102975125 64 24000 20.0000 102915079 69 10800 9.0000 102977473 65 42000 35.0000 =====================s3.cqkr.huayugame.com================================== passportId level num h_count 103214239 65 6000 5.0000 103048907 70 1200 1.0000 103166121 61 2400 2.0000 102906791 64 1200 1.0000 103259853 63 1200 1.0000 103268837 65 1200 1.0000 103270689 69 3600 3.0000

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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

How to determine whether a Golang string ends with a specified character How to determine whether a Golang string ends with a specified character Mar 12, 2024 pm 04:48 PM

Title: How to determine whether a string ends with a specific character in Golang. In the Go language, sometimes we need to determine whether a string ends with a specific character. This is very common when processing strings. This article will introduce how to use the Go language to implement this function, and provide code examples for your reference. First, let's take a look at how to determine whether a string ends with a specified character in Golang. The characters in a string in Golang can be obtained through indexing, and the length of the string can be

How to check if a string starts with a specific character in Golang? How to check if a string starts with a specific character in Golang? Mar 12, 2024 pm 09:42 PM

How to check if a string starts with a specific character in Golang? When programming in Golang, you often encounter situations where you need to check whether a string begins with a specific character. To meet this requirement, we can use the functions provided by the strings package in Golang to achieve this. Next, we will introduce in detail how to use Golang to check whether a string starts with a specific character, with specific code examples. In Golang, we can use HasPrefix from the strings package

How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP How to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP Mar 04, 2024 am 09:36 AM

Methods to solve Chinese garbled characters when converting hexadecimal strings in PHP. In PHP programming, sometimes we encounter situations where we need to convert strings represented by hexadecimal into normal Chinese characters. However, in the process of this conversion, sometimes you will encounter the problem of Chinese garbled characters. This article will provide you with a method to solve the problem of Chinese garbled characters when converting hexadecimal to string in PHP, and give specific code examples. Use the hex2bin() function for hexadecimal conversion. PHP’s built-in hex2bin() function can convert 1

PHP string manipulation: a practical way to effectively remove spaces PHP string manipulation: a practical way to effectively remove spaces Mar 24, 2024 am 11:45 AM

PHP String Operation: A Practical Method to Effectively Remove Spaces In PHP development, you often encounter situations where you need to remove spaces from a string. Removing spaces can make the string cleaner and facilitate subsequent data processing and display. This article will introduce several effective and practical methods for removing spaces, and attach specific code examples. Method 1: Use the PHP built-in function trim(). The PHP built-in function trim() can remove spaces at both ends of the string (including spaces, tabs, newlines, etc.). It is very convenient and easy to use.

PHP String Matching Tips: Avoid Ambiguous Included Expressions PHP String Matching Tips: Avoid Ambiguous Included Expressions Feb 29, 2024 am 08:06 AM

PHP String Matching Tips: Avoid Ambiguous Included Expressions In PHP development, string matching is a common task, usually used to find specific text content or to verify the format of input. However, sometimes we need to avoid using ambiguous inclusion expressions to ensure match accuracy. This article will introduce some techniques to avoid ambiguous inclusion expressions when doing string matching in PHP, and provide specific code examples. Use preg_match() function for exact matching In PHP, you can use preg_mat

How to intercept a string in Go language How to intercept a string in Go language Mar 13, 2024 am 08:33 AM

Go language is a powerful and flexible programming language that provides rich string processing functions, including string interception. In the Go language, we can use slices to intercept strings. Next, we will introduce in detail how to intercept strings in Go language, with specific code examples. 1. Use slicing to intercept a string. In the Go language, you can use slicing expressions to intercept a part of a string. The syntax of slice expression is as follows: slice:=str[start:end]where, s

See all articles