SQL queries the sum of two values as a condition

Source: Internet
Author: User

Purpose: To filter the sum of two fields in a table as a where condition

Querying for records with no expiration
Select a, from Test where a+b>now ();//A: Deposit time B: Validity period

SQL will error when you make the above query.


However, simply put the above SQL into the code and replace now () with the method of the current timestamp obtained by the corresponding language (e.g. time () in PHP), execute, perfect ok!

Analysis: Running this way directly in SQL, SQL will understand now () as the current format time, so after a+b directly understand the normal string, not the concept of the time stamp understood, so that the operation did not get the desired result.

This understanding may not be correct, there is a better answer welcome comment exchange!

SQL queries the sum of two values as a condition

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.