Create a computing field CONCAT in MySQL

Source: Internet
Author: User

When I read the Mysql manual again today, I see a function concatenation field that is ignored at ordinary times. In fact, it is simple to use mysql functions to process strings. The calculated field is usually used, but the spliced field is ignored. Mark it here.

A field (filed) basically has the same meaning as a column and is often used interchangeably. However, a database column is generally a column, and a term field is usually connected to a calculated field.

Table Structure:

 
 
  1. 'Sdb _ bookstore_book','CREATE TABLE'Sdb _ bookstore_book '(
  2. 'Bid'Int(11)NOT NULLAUTO_INCREMENT,
  3. 'Code'Varchar(100)DEFAULT NULL,
  4. 'Bname'Varchar(100)DEFAULT NULL,
  5. 'Author'Varchar(100)DEFAULT NULL,
  6. 'Publish'Varchar(100)DEFAULT NULL,
  7. 'Pubtime'Varchar(100)DEFAULT NULL,
  8. 'Price'Varchar(20)DEFAULT NULL,
  9. 'Language'Varchar(50)DEFAULT NULL,
  10. 'Intime'Date DEFAULT NULL,
  11. 'Quantity'Int(5)DEFAULT NULL,
  12. 'Content'Varchar(500)DEFAULT NULL,
  13. 'City' enum ('Beijing','Shanghai Hongqiao','Shanghai Puyuan')DEFAULT 'Shanghai Puyuan',
  14. 'Tag'Varchar(500)DEFAULT NULL,
  15. 'State' enum ('Shelving','Not on shelf')DEFAULT 'Shelving',
  16. 'Lastname'Varchar(100)DEFAULT NULL,
  17. 'Lasttime'Date DEFAULT NULL,
  18. 'Lastname'Varchar(100)DEFAULT NULL,
  19. 'Lasttime'Date DEFAULT NULL,
  20. 'Remark'Varchar(100)DEFAULT NULL,
  21. 'Img'Varchar(200)DEFAULT NULL,
  22. 'Standrbtime'Date DEFAULT NULL,
  23. 'Amount'Int(5)DEFAULT '0',
  24. 'Isbn'Varchar(13)DEFAULT NULL,
  25. PRIMARY KEY('Bid ')
  26. ) ENGINE = InnoDB AUTO_INCREMENT = 956DEFAULTCHARSET = utf8'

The table contains certain data.

Now I want to extract the author of the field name from the database and then use the name (author) as a Field Layout. Then I can extract the name from the database and splice it with languages, however, mysql functions can be directly spliced here.

 
 
  1. SELECT CONCAT(bname,'(',author,')') AS new_filed FROM sdb_bookstore_book 

Returned data 'Wolf (Liu yongsheng )'

This is the case. The processing in mysql is still relatively fast.

I won't bother here with arithmetic calculation.

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.