Mysql date comparison

Source: Internet
Author: User
Mysql date comparison problems now the table kucun contains datavalue (varchar, in the format of 2012-01-01) and price (float11, 2) now I want to obtain data FROM to. I write this method: 1. SELECT * FROM 'Ku mysql date comparison problem
Now the table kucun contains the datavalue (varchar, in the format of) and price (float) fields.

Now I want to get the data from.

1,
SELECT * FROM 'Kun' where datavalue between 'unix _ TIMESTAMP (2012-07-10) 'and 'unix _ TIMESTAMP (2012-08-10 )'
The result is null.
2,
SELECT * FROM 'Kun' WHERE datavalue BETWEEN '2017-07-10 'AND '2017-08-10'
The result is correct. I have obtained the data I want to find.

3,
SELECT * FROM 'Kun' where UNIX_TIMESTAMP (datavalue)> UNIX_TIMESTAMP (2012-07-10) and UNIX_TIMESTAMP (datavalue) The result is null.

Is 1 and 3 empty? 2 Is it formal? Can a date in a format like XXXX-XX-XX be compared?

------ Solution --------------------
1,
SELECT * FROM 'Kun' where datavalue between 'unix _ TIMESTAMP (2012-07-10) 'and 'unix _ TIMESTAMP (2012-08-10 )'
Extra quotation marks to be deleted

3,
SELECT * FROM 'Kun' where UNIX_TIMESTAMP (datavalue)> UNIX_TIMESTAMP ('2017-07-10 ') and UNIX_TIMESTAMP (datavalue) Quotation marks required
------ Solution --------------------
The string parameter of the UNIX_TIMESTAMP () function must be enclosed in quotation marks, so try:
SQL code
SELECT * FROM `kucun` where UNIX_TIMESTAMP(datavalue)>UNIX_TIMESTAMP('2012-07-10') and UNIX_TIMESTAMP(datavalue)

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.