MySQL Date comparison related issues

Source: Internet
Author: User
MySQL Date comparison problem
The table Kucun now has datavalue (varchar, which is the 2012-01-01 format date) and the price (float 11,2) field

Now I want to get the data from 2012-07-10 to 2012-08-10.

1,
SELECT * from ' Kucun ' where datavalue between ' Unix_timestamp (2012-07-10) ' and ' Unix_timestamp (2012-08-10) '
Result is empty
2,
SELECT * from ' kucun ' WHERE datavalue between ' 2012-07-10 ' and ' 2012-08-10 '
The result is correct, get the data I want to find.

3,
SELECT * from ' Kucun ' where Unix_timestamp (datavalue) >unix_timestamp (2012-07-10) and Unix_timestamp (DataValue)
<>

Result is empty

Why are 1 and 3 empty? 2 is it normal to write like this? Xxxx-xx-xx such a format date can be compared?

------Solution--------------------
1.
SELECT * from ' Kucun ' where datavalue between ' Unix_timestamp (2012-07-10) ' and ' Unix_timestamp (2012-08-10) '
To delete the extra quotes

3.
SELECT * from ' Kucun ' where Unix_timestamp (datavalue) >unix_timestamp (' 2012-07-10 ') and Unix_timestamp (DataValue)
<>

To fill in the necessary quotation marks
------Solution--------------------
The string parameter of the Unix_timestamp () function is quoted, 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.