0
이것은 제가 시도하는 쿼리입니다.MySQL 카운트()가 올바른 숫자를 반환하지 않습니다.
select
UserId,
count(e.UserId) as 'Experiments',
count(t.TaskId) as 'Tasks tried',
count(case when t.TaskStatus = 'Completed' then t.TaskStatus end) as 'Tasks completed',
sec_to_time(avg(timediff(TaskLocalUserEndDateTime,TaskLocalUserStartDateTime))) as 'Average Time'
from
Tasks as t,
Experiments as e
where
t.ExperimentId = e.ExperimentId
and
e.UserId = e.UserId
group by
UserId;
count(e.UserId)
가 잘못 count(t.TaskId)
와 동일한 결과를 제공한다. 내가 어떤 조인하지 않고, 예를 들어, 쿼리를 실행한다면 올바른 결과를 count()
반환이 도움이 될 것입니다
select
count(UserId)
from
Experiments
where
UserId = UserId
group by
UserId;
나머지 쿼리가 작동하고 원하는 결과 집합을 생성합니까? – kabuto178
예, 나머지 열에는 유효한 값이 들어 있습니다. 단지'count (e.UserId)'열에 잘못된 값이 있습니다. –
샘플 데이터를 게시하십시오. –