Special usage of the SELECT command in MySQL

Source: Internet
Author: User
Tags php mysql

The SELECT command in MySQL is often used. The following describes some special usage of the SELECT command in MySQL for your reference.

The SELECT command in MySQL is similar to the print or write command in other programming languages. You can use it to display the results of a string, number, and mathematical expression. How to use the special features of the SELECT command in MySQL?

1. Display MYSQL version

 
 
  1. mysql> select version();  
  2. +-----------------------+  
  3. | version()             |  
  4. +-----------------------+  
  5. | 6.0.4-alpha-community |  
  6. +-----------------------+  
  7. 1 row in set (0.02 sec)  
  8.  

2. display the current time

 
 
  1. mysql> select now();  
  2. +---------------------+  
  3. | now()               |  
  4. +---------------------+  
  5. | 2009-09-15 22:35:32 |  
  6. +---------------------+  
  7. 1 row in set (0.04 sec)  
  8.  

3. Display year, month, and day

 
 
  1. SELECT DAYOFMONTH(CURRENT_DATE);  
  2. +--------------------------+  
  3. | DAYOFMONTH(CURRENT_DATE) |  
  4. +--------------------------+  
  5. |                       15 |  
  6. +--------------------------+  
  7. 1 row in set (0.01 sec)  
  8.    
  9. SELECT MONTH(CURRENT_DATE);  
  10. +---------------------+  
  11. | MONTH(CURRENT_DATE) |  
  12. +---------------------+  
  13. |                   9 |  
  14. +---------------------+  
  15. 1 row in set (0.00 sec)  
  16.    
  17. SELECT YEAR(CURRENT_DATE);  
  18. +--------------------+  
  19. | YEAR(CURRENT_DATE) |  
  20. +--------------------+  
  21. |               2009 |  
  22. +--------------------+  
  23. 1 row in set (0.00 sec)  
  24.  

4. Display strings

 
 
  1. mysql> SELECT "welecome to my blog!";  
  2. +----------------------+  
  3. | welecome to my blog! |  
  4. +----------------------+  
  5. | welecome to my blog! |  
  6. +----------------------+  
  7. 1 row in set (0.00 sec)  
  8.  

5. When using a calculator

 
 
  1. select ((4 * 4) / 10 ) + 25;  
  2. +----------------------+  
  3. | ((4 * 4) / 10 ) + 25 |  
  4. +----------------------+  
  5. |                26.60 |  
  6. +----------------------+  
  7. 1 row in set (0.00 sec)  
  8.  

6. String concatenation

 
 
  1. select CONCAT(f_name, " ", l_name)  
  2. AS Name  
  3. from employee_data  
  4. where title = 'Marketing Executive';  
  5. +---------------+  
  6. | Name          |  
  7. +---------------+  
  8. | Monica Sehgal |  
  9. | Hal Simlai    |  
  10. | Joseph Irvine |  
  11. +---------------+  
  12. 3 rows in set (0.00 sec)  
  13.  

Note: The CONCAT () function is used to concatenate strings. In addition, we also use the previously learned AS to give the result column 'concat (f_name, "", l_name) 'A Kana.

Two methods to fix mysql tables

How to insert an array into a mysql table in php

MySQL Data Table Traversal method

Implementation of batch data import in MySQL

Create a temporary table in php mysql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.