随笔分类 -  SQL

摘要:查询所有用户(mysql库下) select * from user; 创建一个新用户 CREATE USER 'zhong'@'localhost' IDENTIFIED BY '123456'; //只允许本地登录 CREATE USER 'zhong'@'%' IDENTIFIED BY '1 阅读全文
posted @ 2020-06-15 12:04 suruozhong 阅读(350) 评论(0) 推荐(0) 编辑
摘要:当使用union来查询,并分页时 如果数据量很大,很容易造成查询超时,要么就是特别慢 首先我们先分析下数据,是否完全不重复 如果不重复,则使用 union all union all和union的区别是,UNION 操作会对结果去重且排序,所以从速度来说, UNION ALL会更胜一筹 接着,所有的 阅读全文
posted @ 2020-05-08 17:48 suruozhong 阅读(4522) 评论(0) 推荐(0) 编辑
摘要:select * from sys_member where create_time >=(NOW() - interval 24 hour) 七天之前的数据 SELECT * FROM commodity_order where create_time <= (now()-INTERVAL 7 DAY) order by create_time desc 阅读全文
posted @ 2019-10-24 11:55 suruozhong 阅读(2516) 评论(0) 推荐(0) 编辑
摘要:格式化时间 select DATE_FORMAT(create_time,'%Y-%m') from commodity 获取随机一个用户 select *, (FLOOR(0+(RAND()*100))) as num from sys_member order by num desc limit 阅读全文
posted @ 2019-10-14 10:17 suruozhong 阅读(766) 评论(0) 推荐(0) 编辑
摘要:Oracle 查询今日、昨日、本周、本月和本季度的所有记录 字段类型为date 今日 select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd') 昨日 select * from 表名 where to_char(字段名,'dd')= to_char(sysdate-1,'dd') 本周 select * from 表名 ... 阅读全文
posted @ 2016-10-18 19:38 suruozhong 阅读(11012) 评论(0) 推荐(1) 编辑
摘要:今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0 昨天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=1 7天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getd... 阅读全文
posted @ 2016-10-18 19:37 suruozhong 阅读(69456) 评论(0) 推荐(5) 编辑

点击右上角即可分享
微信分享提示