将条件放在可为空的列上 [英] Putting a condition on a nullable column

查看:69
本文介绍了将条件放在可为空的列上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select count(*) from passengermaster where (ticket_issue_date is not null and ticket_issue_date > 2009-01-01);


并不是每位注册乘客都会获得一张票,但是对于那些已经获得票证的乘客,我想算一下
2009年1月1日之后发行的所有票证.
我得到正确的答案,但在良好的措施下,我还会收到错误1292-错误的值.


Not every registered passenger will have been issued a ticket, but for those that have, I want a count of
all tickets issued after 01/01/09.
I am getting the correct answer, but for good measure I also get Error 1292 - Incorrect value.
Any assistance in eliminating the error is much appreciated

推荐答案

您不应该需要... is not null位,因为null不大于任何日期.

错误是因为未引用日期,所以它会将列中的日期与数字2007(2009-1-1)进行比较.

尝试以下方法:
You shouldn''t need the ... is not null bit because null is not greater than any date.

The error is because the date is not quoted, so it is comparing the date in the column with the number 2007 (2009 - 1 - 1).

Try this instead:
select count(*) from passengermaster where ticket_issue_date > ''2009-01-01'';


这篇关于将条件放在可为空的列上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆