自增sql
发表于|更新于
|浏览量:
所谓觉悟,就是在漆黑的荒野上开辟出一条理当前进的道路。——乔鲁诺.乔巴纳
我们可以使用
1 | update user set age=age+1 where id = 1 |
来让age在原来的基础上+1
相关推荐
2020-06-19
mysql使用druid时自动断开连接解决方案
今天接手了一个上了年龄的项目,用的是smm,数据库连接池用的druid,数据库版本较老,是5.0的mysql,我升级成mysql8.0后,一开始还没问题,然后大概每次无连接2分钟后数据库自动断开。。。 前端妹子立马跟我说接口报错了,我咯噔心里一慌,让前端妹子给我截一下报错信息(后台日志刷的太多,当时没注意到)。然后前端妹子说,哦又好了,我当时意识到不对劲,但也没有深究,直到这样的问题出了几次,每次一刷新又好了,我开始意识到问题的严重性。 一开始我复制了报错信息,也就是这一段 123Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failureThe last packet successfully received from the server was 8848 milliseconds ago. The last packet sent successfully to the server was 8848 milliseconds ago. 搜了半天,网上...
2021-01-27
Client does not support authentication protocol requested by server
宿命论是那些缺乏意志力的弱者的借口。——罗曼·罗兰 今天试了试使用js连接数据库,发现报错Client does not support authentication protocol requested by server; consider upgrading MySQL client 乍一看,代码好像没问题 1234567891011121314151617181920var mysql = require("mysql");let connection = mysql.createConnection({ host: "127.0.0.1", port: 3306, user: "root", password: "789456", database: "ruben"});connection.connect();connection.query("select * from user", funct...
2021-04-07
mysql随机查询
明者见危于无形,智者见祸于未萌。——《三国志》 我们如果需要使用mysql进行随机取N条这样的操作 我们可以这样写 12345678-- 2.然后查询主表,与我们的tmp_table进行INNER JOIN[内连]SELECT * FROM `film` AS main_table JOIN -- 1.取出主表主键的最大值,与RAND()相乘[RAND()生成0到1的随机数],然后使用ROUND函数取整获得一个tmp_id(SELECT ROUND(RAND() * (SELECT MAX(`film_id`) FROM `film`)) AS tmp_id) AS tmp_table-- 3.条件为主表主键大于等于tmp_table.tmp_idWHERE main_table.`film_id` >= tmp_table.tmp_id-- 4.排序,限制条数,这里的可以任选ORDER BY main_table.`film_id` LIMIT 5; 这个是我认为效率比较高的随机查询了
2023-02-16
mysql having报错this is incompatible with sql_mode=only_full_group_by
该得到荣誉却未得到,比不该得到荣誉而得到要好得多。——马克·吐温 今天遇到个报错 发现原来是MYSQL 8不支持在sql_mode包含only_full_group_by时(默认包含) HAVING的条件里有 非聚合字段 以外的字段 文档: ONLY_FULL_GROUP_BY Reject queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on (uniquely determined by) GROUP BY columns. A MySQL extension to standard SQL permits references in the HAVING clause to aliased expressions in the select list. The ...
2023-06-06
加唯一索引时候发现已有重复数据删除
说话随便的人,便是没有责任心。——哈代 sql如下 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677-- 查询重复数据idSELECT GROUP_CONCAT( id SEPARATOR ',' )FROM `my_table` GROUP BY `user_id`, `depart_id`, `position_id` HAVING COUNT(*) > 1 AND `user_id` IS NOT NULL AND `depart_id` IS NOT NULL AND `position_id` IS NOT NULL;-- 查询需要删除掉的重复数据SELECT t1.`id`, t1.`user_id`, t1.`depart_id`, t1.`position_id`, t1.`gmt_create...
2023-04-27
SUBSTRING_INDEX
天下兴亡,匹夫有责——顾炎武 分享一个函数 SUBSTRING_INDEX 1SUBSTRING_INDEX( your_column , char, 1 ) 可以像split一样截取片段 例如 1SUBSTRING_INDEX( '1.00' ,'.',1 ) 得到1 例如 1SUBSTRING_INDEX( '1.00' ,'.',-1 ) 得到00
