(筆記)Mysql命令select:當前選擇(串連)的資料庫

來源:互聯網
上載者:User

標籤:

 

select命令表示當前選擇(串連)的資料庫。

select命令格式:mysql> select database();

MySQL中SELECT命令類似於其他程式設計語言裡的print或者write,你可以用它來顯示一個字串、數字、數學運算式的結果等等。如何使用MySQL中SELECT命令的特殊功能呢?

1) 顯示MYSQL的版本
mysql> select version(); 
+-----------------------+ 
| version()               | 
+-----------------------+ 
| 6.0.4-alpha-community | 
+-----------------------+ 
1 row in set (0.02 sec) 

2) 顯示目前時間
mysql> select now(); 
+---------------------+ 
| now()                 | 
+---------------------+ 
| 2009-09-15 22:35:32 | 
+---------------------+ 
1 row in set (0.04 sec) 

3) 顯示年月日
SELECT DAYOFMONTH(CURRENT_DATE); 
+--------------------------+ 
| DAYOFMONTH(CURRENT_DATE) | 
+--------------------------+ 
|                       15       | 
+--------------------------+ 
1 row in set (0.01 sec) 
  
SELECT MONTH(CURRENT_DATE); 
+---------------------+ 
| MONTH(CURRENT_DATE) | 
+---------------------+ 
|                   9      | 
+---------------------+ 
1 row in set (0.00 sec) 
  
SELECT YEAR(CURRENT_DATE); 
+--------------------+ 
| YEAR(CURRENT_DATE) | 
+--------------------+ 
|               2009   | 
+--------------------+ 
1 row in set (0.00 sec) 

4) 顯示字串
mysql> SELECT "welecome to my blog!"; 
+----------------------+ 
| welecome to my blog! | 
+----------------------+ 
| welecome to my blog! | 
+----------------------+ 
1 row in set (0.00 sec) 

5) 當計算機用
select ((4 * 4) / 10 ) + 25; 
+----------------------+ 
| ((4 * 4) / 10 ) + 25 | 
+----------------------+ 
|                26.60    | 
+----------------------+ 
1 row in set (0.00 sec) 

6) 串接字串
select CONCAT(f_name, " ", l_name) 
AS Name 
from employee_data 
where title = ‘Marketing Executive‘; 
+---------------+ 
| Name          | 
+---------------+ 
| Monica Sehgal | 
| Hal Simlai    | 
| Joseph Irvine | 
+---------------+ 
3 rows in set (0.00 sec) 

注意:這裡用到CONCAT()函數,用來把字串串接起來。另外,我們還用到以前學到的AS給結果列‘CONCAT(f_name, " ", l_name)‘起了個假名。

 

(筆記)Mysql命令select:當前選擇(串連)的資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.