MySQL中遇到的几种报错及其解决方法 1.[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''xxx'' at line 1 解决方法:将所有的" '' "换成" ·· "(将所有的英文单引号换为Tab键上面的那个点号)…
浅谈MySQL中优化sql语句查询常用的30种方法 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 3.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is null 可以在num上设置默认值0,确保表中num列没有nul…
一.字符串转日期 下面将讲述如何在MYSQL中把一个字符串转换成日期: 背景:rq字段信息为:20100901 1.无需转换的: SELECT * FROM tairlist_day WHERE rq>'2010-07-31' AND rq<'2010-09-01' 2.使用:DATE_FORMAT SELECT * FROM tairlist_day WHERE DATE_FORMAT( rq, '%Y-%m-%d')>'2010-08-01' AND DATE_FORMAT( rq,…
假如有个表product有个字段add_time,它的数据类型为datetime,有人可能会这样写sql: select * from product where add_time = '2013-01-12' 对于这种语句,如果你存储的格式是YY-mm-dd是这样的,那么OK,如果你存储的格式是:2013-01-12 23:23:56这种格式你就悲剧了,这是你就可以使用DATE()函数用来返回日期的部分,所以这条sql应该如下处理: select * from product where Da…
方法1:$.extend({ myTime: { CurTime: function () { return Date.parse(new Date()) / 1000; }, DateToUnix: function (string) { var f = string.split(' ', 2); var d = (f[0] ? f[0] : '').split('-', 3); var t = (f[1] ? f[1] : '').split(':', 3); return (new Dat…
1.concat()函数 2.concat_ws()函数 3.group_concat()函数 操作的table select * from test_concat order by id limit 5; 1.concat()函数 功能:将多个字符串连接成一个字符串. 语法:concat(str1, str2,...),返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null. 3.举例: select concat(area,fr,best_history_data)…
技术交流群:233513714 1.日期无需转换查询(日期在数据库中的类型为字符串) select * from day where dateTime > '2016-03-15' 2.使用date_format select * from day where date_format(dateTime,'%Y-%m-%d') > '2016-03-15' 3.日期转换还可以使用str_to_date() select str_to_date(dateTime,'%Y-%m-%d %H:%i:%…
from_unixtime(unix_timestamp, format) 把时间戳转化为指定的格式 as: select from_unixtime(addTime, '%Y-%m-%d %h:%i:%s') as datetime from table1 unix_timestamp([datetime]) 把日期时间转化为时间戳 as: select from_unixtime([addDay]) as unixtime from table1 case(value as type) co…