MySQL时间转换/字符串截取/
2015-09-06 17:35
666 查看
字符串截取:
SELECT SUBSTRING('abcdefg',2,5)
计算字符长度:
len(string)
--查询2010前入学入学ID select user from cf_log where substr(user,0,4)<2010 order by user ASC limit 0,10;
统计元组数:
select count(*) from cf_user;
查询重复:
select count(user),user,pwd,name from cf_user group by user having count(user)>1;
查询结果插入表中:
insert into cf_grade1 select * from cf_grade where user='' order by term;
insert into cf_user(user,pwd,name,degree,dept,major,class,year) select distinct user,pwd,name,degree,dept,major,class,year from cf_log;
insert into ims_goods_3(model,name,price) select model,name,price from ims_goods_5 order by model;
去重:
delete from 表 where ID not in (select max(ID) from 表 group by 重复列);
时间戳转换星期:
DAYOFWEEK() 星期天:1,星期一:2…………--查询星期天的记录 select * from d where DAYOFWEEK(FROM_UNIXTIME(time))=1;
获取当前时间:
select localtime(); select now(); --current_timestamp(),效果一样
获取YYYY-MM-DD日期
select curdate();--2015-09-06
动态时间:
sysdate()
年月日转换:
set @dt = now(); select dayofweek(@dt); -- 1 select dayofmonth(@dt); -- 6 select dayofyear(@dt); -- 249 返回当前年份第多少天
查询指定月份最后一天日期:
select last_day(now()); -- 2015-09-30
两个日期时间差[返回int型]:
若第一个参数小于第二个参数返回结果为负数
select datediff(now(),'2015-08-28');
字符串截取:
SELECT SUBSTRING('abcdefg',2,5)
计算字符长度:
len(string)
--查询2010前入学入学ID select user from cf_log where substr(user,0,4)<2010 order by user ASC limit 0,10;
查询重复:
select count(user),user,pwd,name from cf_user group by user having count(user)>1;
查询结果插入表中:
insert into cf_grade1 select * from cf_grade where user='' order by term; insert into cf_user(user,pwd,name,degree,dept,major,class,year) select distinct user,pwd,name,degree,dept,major,class,year from cf_log;
去重:
delete from 表 where ID not in (select max(ID) from 表 group by 重复列);
查询每门课程最高分学生的信息:
select name,A.user,A.score from (select user,cname,max(score) AS score from cf_grade group by cname) A,cf_user B where A.user=B.user;
相关文章推荐
- 安装mysql报curses的解决
- MySql主从复制测试记录
- Ubuntu 下安装Mysql 需要注意的地方.
- mysql数据库查询整理
- sqlite导入到mysql
- mysql开启远程访问
- mysql 数据库操作语句备忘
- mysql查看在线以及重启
- mysql 中的GROUP BY
- MySQL学习----MySQL数据类型----03MySQL 日期和时间类型
- MySQL学习----MySQL数据类型----02MySQL 字符类型
- MySQL学习----MySQL数据类型----01MySQL 数值类型
- mysql在ubuntu上的安装过程
- mysql怎么查询条件以另一个表中条件进行查询
- Mysql复合主键中自增长字段
- MySQL中修改数据库引擎方法
- Mysql初始化root密码和允许远程访问
- mysql 中索引的限制
- mysql重做日志
- 源码编译安装mysql5.6报错及解决方法