sql
进击的中国学渣
努力也许改变不了一切,但能改变许多
展开
-
mysql取某个范围内的随机时间
SELECT FLOOR(7 + (RAND() * 6)); 取7到12的随机整数,包括7到12 SELECT FLOOR(12+(rand()*13)); 取12到24的随机整数,包括12到24 LPAD(FLOOR(0 + (RAND() * 23)),2,0) 取0-24之间的随机数,不够2位的前补0 格式 : 2008-12-11 17:43:11 举例: 给用户赋一个随转载 2017-09-01 20:26:34 · 1090 阅读 · 0 评论 -
mysql 共享锁和排他锁
关于mysql的共享锁和排它锁,有一个不错的博客http://www.cnblogs.com/boblogsbo/p/5602122.html转载 2017-09-09 17:06:09 · 164 阅读 · 0 评论 -
mysql求2个时间的时间差,mysql求绝对值
记录2个mysql函数 1 求2个时间的时间差TIMESTAMPDIFF(DAY,'2017-03-01','2016-03-05')其中DAY可以换成月份,年,秒 2 求绝对值ABS(-19)原创 2017-09-04 22:52:18 · 9567 阅读 · 0 评论 -
sql常用语句(1)
1sql语句求并集 select name from A union select name from B union 这种方法会自动去重,假设我们不去重,就是union all 2 sql语句求交集 select name from A intersect s原创 2017-02-15 20:08:25 · 240 阅读 · 0 评论 -
存储过程初步学习
最近因为需要用到了存储过程,简单介绍一下存储过程。先上一个demodrop procedure wsy_test;DELIMITER //create procedure wsy_test()begin DECLARE no_more_products, prd_code int default 0; -- 定义变量 DECLARE cur_product CURSOR FOR原创 2017-08-22 23:50:59 · 211 阅读 · 0 评论 -
mysql中You can't specify target table for update in FROM clause错误
mysql中You can’t specify target table for update in FROM clause错误意思你不可以对某个表现进行select,然后根据select出来的值再进行操作。比如:update tbl tset t.name = 'xxx'where id in ( select max(id) from tbl a where EXISTS原创 2017-08-07 14:55:36 · 190 阅读 · 0 评论 -
mysql筛选条件执行顺序
from on join where group by having select distinct union order by 这个顺序其实是很重要,用的好能够提升你的查询效率,比如说以下语句1:select A.ID as AID, B.ID as BID from A left join B on A.ID = B.ID where B.ID<3原创 2017-08-07 14:24:17 · 1566 阅读 · 0 评论 -
delete和truncate的区别
delete可以加where语句针对筛选条件进行部分删除,删除成功返回删除的条数所以相对比较慢。而且delete语句并不会让id重新从1开始。delete from tableName删除所有记录,重新插入数据id并不会从1开始delete from tableName where id > 1删除id>1的记录truncate是清楚整张表的意思,并不用关心这个表有多少记录,也不能加where语句直原创 2017-08-07 10:46:30 · 229 阅读 · 0 评论 -
join,left join,inner join,right join的区别
left join是以A表的记录为基础的,A可以看成左表,B可以看成右表,left join是以左表为准的.换句话说,左表(A)的记录将会全部表示出来,而右表(B)只会显示符合搜索条件的记录(例子中为: A.aID = B.bID).B表记录不足的地方均为NULL.举个例子A B原创 2017-06-28 11:30:51 · 154 阅读 · 0 评论 -
如何查看mysql当前未提交的事物
到information_schema库下面,查看下面这个表: innodb_trx ## 当前运行的所有事务 innodb_locks ## 当前出现的锁 innodb_lock_waits ## 锁等待的对应关系原创 2017-11-24 14:38:23 · 3870 阅读 · 0 评论