Home  >  Article  >  Database  >  mysql advanced (19) How to accurately find data in a certain time period using SQL statements

mysql advanced (19) How to accurately find data in a certain time period using SQL statements

黄舟
黄舟Original
2017-02-10 11:10:331644browse

How to accurately search for data in a certain period of time using SQL statements

During the project development process, you need to query the transactions within a certain period of time. Therefore, it is necessary to add date and time elements to the sql query statement. How to implement the sql statement?

SELECT * FROM lmapp.lm_bill where tx_time Between '2015-12-20' And '2015-12-31' ;

Careful study can still reveal some detailed issues.

SQLStatement1

## SELECT * FROM lmapp.lm_bill where merch_uid='S18853883587' AND tx_time Between '2015-09-17' AND '2015-10-27 24:00:0';

Query results1

## SQL

Statement2## SELECT * FROM lmapp.lm_bill where merch_uid='S18853883587' AND tx_time Between '2015-09-17

0:00:0' AND '2015-10-27 24:00:0'; Query results

2

## SQLStatement

3## SELECT * FROM lmapp.lm_bill where merch_uid='S18853883587' AND tx_time Between '2015-09-17' AND '2015 -10-27';

Query results3

Through comparison, it can be clearly found that the query results corresponding to the above three SQL statements are different. If you want to only use date as the query condition and ignore time, you need to further process the sql statement.

Data storage situation in the database:

It can be seen that

SQL

statement

1

is a query statement that satisfies the conditions. The above is the content of mysql advanced (nineteen) SQL statements on how to accurately find data in a certain time period. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn