Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL在where子句中使用日期_Sql_Inner Join_Where - Fatal编程技术网

SQL在where子句中使用日期

SQL在where子句中使用日期,sql,inner-join,where,Sql,Inner Join,Where,我这里有这个SQL代码 SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, (SELECT COUNT(*) FROM invoice HERE client = cl.clientid) AS invoicecount FROM client cl INNER J

我这里有这个SQL代码

SELECT cl.clientid,
       cl.clientname,
       cl.billingdate,
       cp.startdate,
       cp.expiration, 
       (SELECT COUNT(*)
            FROM invoice 
            HERE client = cl.clientid) AS invoicecount  
FROM client cl
INNER JOIN clientplan cp ON cp.client = cl.clientid
WHERE cl.isbilled = 1 AND expiration is NULL AND expiration > '2012-06-22'
我的问题是,一个客户可能有3个客户计划,它们要么有到期日,要么到期日为空。我正在尝试获取未过期或为空的行


我做错了什么?

我不确定,但这不是你想要的:

SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, 
(select count(*) from invoice where client = cl.clientid) as invoicecount  
FROM client cl
inner join clientplan cp on cp.client = cl.clientid
where cl.isbilled = 1 and (expiration is NULL or expiration > '2012-06-22')

在到期时使用或代替和。因为过期日期不能为空,并且>'2012-06-22'…

我不确定,但这不是您想要的:

SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, 
(select count(*) from invoice where client = cl.clientid) as invoicecount  
FROM client cl
inner join clientplan cp on cp.client = cl.clientid
where cl.isbilled = 1 and (expiration is NULL or expiration > '2012-06-22')

在到期时使用或代替和。因为过期日期不能为null,并且>'2012-06-22'…

如果日期为null,则永远不会有值。。因此,它要么是过期为空,要么是(过期不为空,过期>'2012年6月22日')[/edit]
并不意味着
这些记录和那些记录
它意味着
其中这是真的,那是真的
。在您的情况下,您不能让
到期为空
到期>'2012-06-22'
同时为真。您的意思是
cl.isbilled=1和(过期为空或过期为“2012-06-22”)
作为旁注,它可能值得添加到您今天的sql实现版本中。例如,在postgres its now()中,如果日期为空,则永远不会有值。。因此,它要么是过期为空,要么是(过期不为空,过期>'2012年6月22日')[/edit]
并不意味着
这些记录和那些记录
它意味着
其中这是真的,那是真的
。在您的情况下,您不能让
到期为空
到期>'2012-06-22'
同时为真。您的意思是
cl.isbilled=1和(过期为空或过期为“2012-06-22”)
作为旁注,它可能值得添加到您今天的sql实现版本中。例如,在postgres its now()中