【发布时间】:2020-09-09 22:00:37
【问题描述】:
我有一个带有字段 meeting_start_date、call_start_date 的表格报告和一个我想与另一个带有字段值的表格 dcalendar 连接的表格。现在可以从我的查询中选择类型
select
a.id,a.meeting_start_date,a.call_start_date
from
report as a
left join
dcalendar b
on b.datevalue=a.meeting_start_date
left join
dcalendar c
on c.datevalue=a.call_start_date
where
(a.lead_stage_c='test')
and
(b.datevalue > '2020-07-31' and b.datevalue < '2020-08-05')
or
( c.datevalue > '2020-07-31' and c.datevalue < '2020-08-05')
and
type='test'
dcalender
id datevalue
1 "2020-08-01 00:00:00"
2 "2020-08-02 00:00:00"
3 "2020-08-03 00:00:00"
4 "2020-08-04 00:00:00
5 "2020-08-05 00:00:00"
我想在报告表中选择 meeting_start_date 或 call_start_date 中 dcalender 表 dvalue 大于“2020-08-01”且小于或等于“2020-08-04”的行。
在我的示例中,我需要选择 1,2,3,4,5 试过了
我在查询中做错了什么
【问题讨论】:
-
将长查询布置为单行几乎无法阅读,因此我为您重新格式化。随意调整样式,但请不要发布单行查询。至于猜测,您在 where 子句中的括号是错误的。 Probaby想要在
OR的两个部分周围增加()