来源:自学PHP网 时间:2015-04-16 10:51 作者: 阅读:次
[导读] 1 字段自减UPDATE `table_name` SET `total`=IF(`total` 1, 0, `total`-1) WHERE `id` = 1;一般在做字段减法的时候我们需要在外部判断一次数 20540;这样可以省去一次外部数 20540;判...
1. 字段自减 UPDATE `table_name` SET `total`=IF(`total` < 1, 0, `total`-1) WHERE `id` = 1;
2. UPDATE 的 SET 使用子查询数据 UPDATE `bz_xs_chapter` AS c, (SELECT COUNT(*) AS total FROM `bz_xs_chapter` WHERE `bookId` = 22042) AS c1, (SELECT COUNT(*) AS total FROM `bz_xs_tome` WHERE `bookId` = 22372) AS c2 SET `c`.`name`=`c1`.`total`, `c`.`words`=`c2`.`total` WHERE `c`.`id` = 2889820
3. COUNT(*)效率高
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com