1 刪除數據庫中某個字段重複的數據 只去第一條 剩下的刪除
DELETE from article where id not in(select a.id from (SELECT * from article) a INNER JOIN(SELECT id from article GROUP BY article) b ON a.id=b.id)
2 oracle數據庫中sql獲取前一天的日期
to_char(sysdate-1,'yyyyMMdd') 格式化爲yyyyMMdd類型
3 mysql格式化日期
select count(*) from user where str_to_date(addtime,'%Y-%m-%d') ='2017-03-12'
4 讓sql語句不排序,按照in語句的順序返回結果
select * from user where userid in('104','came','244','105','260','253','38') order by INSTR(',104,"came",244,105,260,253,', concat(',', userid, ','))
如上
因爲有英文,如果不加引號就會報錯。在in的條件中但是沒在後面instr中的話會排在第一個出現,英文會接下來出現,然後纔是按照instr裏指定的順序。
select * from user where userid in('104','came','244','105','260','253','38') order by INSTR(',"104","came","244","105","260","253",', concat(',', userid, ','))
instr加上引號後,不排序。
參考 http://blog.csdn.net/liyanhui1001/article/details/8508192