MySQL時間轉換/字串截取/

來源:互聯網
上載者:User

標籤:

字串截取:
SELECT SUBSTRING(‘abcdefg‘,2,5)
計算字元長度:
len(string)
--查詢2010前入學入學IDselect 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); -- 1select dayofmonth(@dt); -- 6select dayofyear(@dt); -- 249 返回當前年份第多少天


查詢指定月份最後一天日期:
select last_day(now()); -- 2015-09-30


兩個日期時間差[返回int型]:

若第一個參數小於第二個參數返回結果為負數

select datediff(now(),‘2015-08-28‘);


MySQL時間轉換/字串截取/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.