MySQL: Two fields merge, character time to timestamp, and name field as a Where condition query

Source: Internet
Author: User

There are fields, a, B:

A saved: 2016-10-10

B Saved is: 10:15:30

MySQL merges the fields :

Concat (A, '-', b) or concat (A, ", b)

Character time to time stamp

Unix_timestamp (Concat (A, ", b))

The Name field as the Where condition:

There is a special rule in MySQL that column aliases are not allowed as query criteria. For example, there is a table below:

Select
Id
Title
Concept
Conceptlength,
Adduserid,
Modifytime
From Collections_wisdom

Modify the SQL as follows:

Select
Id+1 as NewID,
Title
Concept
Conceptlength,
Adduserid,
Modifytime
From Collections_wisdom
where NewID>2

Then, there will be an exception to execute:statementcallback; bad SQL grammar

Really to execute, had to put the new field composition in the condition to be realized again, as follows:

Select
Id+1 as NewID,
Title
Concept
Conceptlength,
Adduserid,
Modifytime
From Collections_wisdom
where (id+1)>2

A column alias is not allowed in MySQL as a query condition, it is said that the alias of the column in MySQL is originally displayed when the result is returned, not in SQL parsing. Before there is no more convincing explanation, right vote as such.

Alternatively, you can put the merged characters directly in the where :

Unix_timestamp (Concat (A, ', b)) BETWEEN:startTime:AND:endTime:

MySQL: Two fields merge, character time to timestamp, and name field as a Where condition query

Related Article

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.