Home > Database > Mysql Tutorial > body text

Example tutorial on processing special sql statements in mysql

Y2J
Release: 2017-05-22 15:44:12
Original
1917 people have browsed it

The following editor will bring you a summary of the special processing statements of mysql's sql statements (must read). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

1. Update the entire table. If the value of a column in a row of data is empty, then let it and another The values ​​of a column of fields are equal

UPDATE ot_tgbz set update_day=if(update_day is null,date,update_day);
Copy after login

2,Update the entire table, if a field is greater than 2, then update them all to 2;

UPDATE ot_user set xingyun_num=if(xingyun_num > 2,2,xingyun_num);
Copy after login

3, Replace all URLs containing http://www.jb51.net/ in the thumb field in the shop_goods table with empty ones.

update shop_goods  set thumb= replace (thumb,'http://www.jb51.net/','') where thumb like '%http://www.jb51.net/%';
Copy after login

4、sql statement multi-field wherequery

$map= " CAST(
  `UE_account` AS CHAR CHARACTER
     SET utf8
  ) LIKE '%$data%'
  OR CAST(
    `UE_accName` AS CHAR CHARACTER
    SET utf8
  ) LIKE '%$data%'
  OR CAST(
    `UE_truename` AS CHAR CHARACTER
    SET utf8
  ) LIKE '%$data%'
  OR CAST(
    `UE_phone` AS CHAR CHARACTER
    SET utf8
  ) LIKE '%$data%'";
Copy after login

[Related recommendations]

1. Mysql free video tutorial

2. Detailed explanation of how to write sql statements to delete tables in different databases

3. mysql 5.7 Detailed explanation of the example of changing the database data storage location

4. Detailed explanation of the error reporting method when importing mysql big data into Navicat

5. MYSQL unlock Detailed explanation of examples of lock tables

The above is the detailed content of Example tutorial on processing special sql statements in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!