mysql資料庫中查詢時間

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   for   

項目中要對資料按時間處理,在資料庫中,時間處理的格式如

2014-12-09 06:30:17

時間查詢出來如下所示:

現在要查詢具體有哪天的資料,應用substring函數,SQL如下:

select distinct substring(( start_time ) from 1 for 10) as t from perf_service_msg;

查詢結果如下:

+------------+| t          |+------------+| 2014-12-08 || 2014-12-05 || 2014-11-20 || 2014-12-02 || 2014-12-07 || 2014-12-06 || 2014-12-03 || 2014-12-04 || 2014-11-21 |+------------+9 rows in set

MYSQL中SUBSTRING的說明:

 SUBSTR(str,pos), SUBSTR(str FROM pos), SUBSTR(str,pos,len), SUBSTR(str FROM pos FOR len)SUBSTR() is a synonym for SUBSTRING(). SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are standard SQL syntax. It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning. A negative value may be used for pos in any of the forms of this function.For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.mysql> SELECT SUBSTRING(‘Quadratically‘,5);        -> ‘ratically‘mysql> SELECT SUBSTRING(‘foobarbar‘ FROM 4);        -> ‘barbar‘mysql> SELECT SUBSTRING(‘Quadratically‘,5,6);        -> ‘ratica‘mysql> SELECT SUBSTRING(‘Sakila‘, -3);        -> ‘ila‘mysql> SELECT SUBSTRING(‘Sakila‘, -5, 3);        -> ‘aki‘mysql> SELECT SUBSTRING(‘Sakila‘ FROM -4 FOR 2);        -> ‘ki‘This function is multibyte safe.If len is less than 1, the result is the empty string.

參考:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr

 

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.