MYSQL 基本语句

1.update

update table1,table2,table3

set table1 = 1

where table1.id = table2.clum

and table2.id = table3.clum;

注:在更新某条记录的字段,并且该记录无法直接拿到,与其他表有关联,那么需要将所有的关联表(WHERE 条件中的表)写到 UPDATE 的后面。

2.SELECT

SELECT IF(`status` = 1 ,1,0) AS S FROM table1 WHERE `status` != 2;

在SQL语句中进行判断,IF(`status` = 1 ,1,0) : 如果 `status` 为 1 ,给 1 ;如果不为 1 ,给 0。

3.INSERT
INSERT INTO table(`id`,`name`,`year`,`money`)

SELECT `id`,'测试',1,`money`

FROM table2 WHERE `status` != 0;

多条记录插入,可以在SELECT 中 写入包括 数字/字符串/变量等。

原文地址:https://www.cnblogs.com/wsh-ning/p/9145885.html