简体   繁体   中英

sql query between date not picking up row

Between dates is excluding the last date?

See below: (show all includes SO47 on 2018-06-30)

SELECT order_number , requested_ship_date FROM tv_sales_orders

生的

When I do between statment:

SELECT order_number , requested_ship_date FROM tv_sales_orders WHERE requested_ship_date between '2018-06-01' and '2018-06-30'

There is NO SO47 which is on the 2018-06-30?

SQL查询

Please use below query to get the data:

SELECT order_number, requested_ship_date FROM tv_sales_orders WHERE CAST( requested_ship_date AS DATE) BETWEEN '2018-06-01' AND '2018-06-30';

Hope this works according to your requirement.

The '2018-06-30 12:00:00' is not being retrieved by your query because it is greater than '2018-06-30'. The reason it is greater is because you are not providing time with '2018-06-30' and the DBMS is appending default time with it ie'2018-06-30 00:00:00' which is less than '2018-06-30 12:00:00'. Try providing time in both values in the condition ie between '2018-06-01 00:00:00' and '2018-06-30 23:59:59' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM