MySQL中SELECT命令大家都經常在用,下面為您介紹的是MySQL中SELECT命令的幾種特殊用法,供您參考學習之用。
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表的兩種方法
php中數組插入mysql表的方法
MySQL遍歷數據表的方法
MySQL批量導入數據的實現
php mysql創建臨時表