0

我这里有这个 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 个客户计划,它们要么有一个到期日期,要么到期为 NULL。我正在尝试获取未过期或为 NULL 的行。

我究竟做错了什么?

4

1 回答 1

4

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

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')

用 or 代替 and 到期。因为过期不能为 null 并且 > '2012-06-22'...

于 2012-06-22T15:04:15.953 回答