Select语句给出正确的结果,但在创建表中使用时产生错误:错误1411(HY000):日期时间值不正确:函数str_to_date 。有什么建议吗?
SELECT extraction_id,invoice_date from extracted_fields
WHERE nullif(str_to_date(invoice_date,'%Y-%m-%d'),FROM_DAYS(0)) >= '2017-04-01'
AND nullif(str_to_date(invoice_date,'%Y-%m-%d'),FROM_DAYS(0)) <= '2018-03-31';
| 210147 | 2017-09-27 |
| 210150 | 2017-10-05 |
| 210208 | 2018-03-22 |
| 210211 | 2018-03-26 |
| 210214 | 2018-03-27 |
| 210453 | 2018-02-09 |
| 210463 | 2017-11-30 |
| 210594 | 2018-03-28 |
| 210663 | 2017-12-05 |
+---------------+--------------+
51968 rows in set, 24328 warnings (0.21 sec)
mysql> CREATE TABLE `tmp_2017-18_list_subu`
-> AS
-> SELECT extraction_id,invoice_date from extracted_fields
-> WHERE nullif(str_to_date(invoice_date,'%Y-%m-%d'),FROM_DAYS(0)) >= '2017-04-01'
-> AND nullif(str_to_date(invoice_date,'%Y-%m-%d'),FROM_DAYS(0)) <= '2018-03-31';
ERROR 1411 (HY000): Incorrect datetime value: '' for function str_to_date
mysql> SELECT @@VERSION;
+-------------------------+
| @@VERSION |
+-------------------------+
| 5.7.24-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.00 sec)
谢谢
Subu