我有返回正确结果的 SQL。
select accounts.name, count( case when ((( estimated_start_date<='2013-01-01'
and project.status='closed')
or ( estimated_start_date<='2013-01-01' and project.status='open'
and estimated_end_date>='2013-04-01')))
then 1 else null end) as Number
from project
inner join project_cstm on project.id=project_cstm.id_c
inner join accounts on project_cstm.account_id_c=accounts.id
group by accounts.name
我给了我很好的结果:
例如:
Telenor 5
Telecom 3
现在我想BOOKED_DATE
在WHERE
子句中添加新字段以限制项目数量,仅在该时间间隔内创建一些项目任务。所以我用表做 INNER JOIN,inner join project_task
结果应该更小,但结果却是我得到了这些巨大的数字。不知道如何组合它。
感谢帮助
Telenor 150
Telecom 980
select accounts.name, count( case when ((( estimated_start_date<='2013-01-01'
and project.status='closed')
or ( estimated_start_date<='2013-01-01' and project.status='open'
and estimated_end_date>='2013-04-01')))
then 1 else null end) as Number
from project
inner join project_cstm on project.id=project_cstm.id_c
inner join accounts on project_cstm.account_id_c=accounts.id
inner join project_task on project_task.project_id=project.id
where booked_date>'2013-01-01' and booked_date<'2015-01-01'
group by accounts.name
由于表 PROJECT_TASK 中的行,我得到的结果远非正确。如何限制它?我试过推杆,... count(distinct case when ...
但结果总是 1。
所以我必须以某种方式限制这个值,而不是我