How to solve SQL statements

Source: Internet
Author: User
SQL statement guidance table name: & nbsp; table1 & nbsp; field: & nbsp; id & nbsp; value (numbers plus commas/numbers are not sure) content A: & nbsp; 1 & nbsp; 3,5 content B: & nbsp; 2 & nbsp; 3,3 content C: & nbsp; 3 & nbsp; & SQL statements
Table name: table1
Field: id value (the number plus a comma/number is not sure)
Content A: 1, 3, 5
Content B: 2, 3
Content C: 3, 4, 5
Content D: 4, 3, 6
What I want to achieve is to find the corresponding id and replace 3 with 4 in the value field with only one

The final effect
Content A: 1, 4, 5
Content B: 2, 3
Content C: 3, 4, 5
Content D: 4, 4, 6

SQL statement: SQL php mysql shared:
------ Solution --------------------
Oracle and mysql are not tested. you can replace the corresponding function with mysql.
Select replace (firstStr,'s ', 'A ')
------ Solution --------------------
SecondStr
From (SELECT substr (str, 0, instr (str,'s ') firstStr,
Substr (str, instr (str,'s ') + 1) secondStr
FROM (select t1.value str from table1 t1 where t1.id = 1 ))
------ Solution --------------------
Sorry, I forgot to change the character.
Oracle and mysql are not tested. you can replace the corresponding function with mysql.
Select replace (firstStr, '4', '3 ')
------ Solution --------------------
SecondStr
From (SELECT substr (str, 0, instr (str, '4') firstStr,
Substr (str, instr (str, '4') + 1) secondStr
FROM (select t1.value str from table1 t1 where t1.id = 1 ))
------ Solution --------------------
Select replace (firstStr, '3', '4 ')
------ Solution --------------------
SecondStr
From (SELECT substr (str, 0, instr (str, '3') firstStr,
Substr (str, instr (str, '3') + 1) secondStr
FROM (select t1.value str from table1 t1 where t1.id = 1 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.