我有以下代码:
select ifnull(c.clientid,0) as ClientID, c.surname as Surname, c.addr1 as Address1, c.postcode as Postcode
from cust c
where (c.tour_date between '2019-06-10' and '2019-06-18')
and (c.tour_date between '2019-07-15' and '2019-07-23')
group by ClientID, Surname, Address1, Postcode
order by ClientID asc
而且它不起作用-我想做的是在两组日期之间选择日期。传统上,我们只会选择2019-06-10和2019-07-23,但我们包括的许多客户不应该包括在内。
没关系,我将and
更改为or
,它正在工作,傻瓜!
EDIT2:啊,实际上,当我使用or
时,我得到了2,005个客户端,但是当我做两个单独的提取时,我得出了2,029个客户端。有什么想法吗?
答案 0 :(得分:0)
您有更多的客户在不同的查询中,因为有些客户在两个日期范围之间都有记录。您的group by子句会删除重复项。