이 쿼리는 엔지니어가 시간, 일, 주, 월로 세분화 한 총 테스트 수를 얻기 위해 동일한 테이블 (qcheck)에 대해 여러 카운트를 실행합니다. 또한 결과와 데이터의 스크린 샷을 포함 시켰습니다.하위 쿼리로 롤업 사용
은 내가 합계를 얻을 수 있도록 롤업 싶어하지만 난 아무것도
코드 전체에 가입 할 수 있습니다으로 하위 쿼리를 사용할 때이 작업을 수행하는 방법을 잘 :
를select coalesce(main.checkby, 'Total') as checkby_or_total,
lfaulty,
lfully,
ltotal,
dfaulty,
dfully,
dtotal,
wfaulty,
wfully,
wtotal,
mfaulty,
mfully,
mtotal
from (
select qcheck.checkby,
count(case result when 'fully tested & working' then 1 end) as mfully,
count(case result when 'faulty' then 1 end) as mfaulty,
count(*) as mtotal
from qcheck
where YEAR(finishdate) = YEAR(CURDATE()) AND MONTH(finishdate) = MONTH(CURDATE())
and qcheck.checkby not like 'michael'
and qcheck.checkby not like 'chaz'
group by qcheck.checkby with rollup
) as main
Left join (select qcheck.checkby,
count(case result when 'fully tested & working' then 1 end) as dfully,
count(case result when 'faulty' then 1 end) as dfaulty,
count(*) as dtotal
from qcheck
where finishdate >= now()-interval 12 hour
and qcheck.checkby not like 'michael'
and qcheck.checkby not like 'chaz'
group by qcheck.checkby with rollup) as today on today.checkby =main.checkby
Left join (select qcheck.checkby,
count(case result when 'fully tested & working' then 1 end) as wfully,
count(case result when 'faulty' then 1 end) as wfaulty,
count(*) as wtotal
from qcheck
where YEARWEEK(finishdate)=YEARWEEK(NOW())
and qcheck.checkby not like 'michael'
and qcheck.checkby not like 'chaz'
group by qcheck.checkby with rollup) as week on week.checkby =main.checkby
Left join (select qcheck.checkby,
count(case result when 'fully tested & working' then 1 end) as lfully,
count(case result when 'faulty' then 1 end) as lfaulty,
count(*) as ltotal
from qcheck
where finishdate >= now()-interval 1 hour
and qcheck.checkby not like 'michael'
and qcheck.checkby not like 'chaz'
group by qcheck.checkby with rollup) as month on month.checkby =main.checkby
order by main.checkby is null,
mtotal desc
두 번째 그림은 * 원하는 * 출력입니까, 아니면 * 현재 * 출력입니까? * 원하는 * 출력이 아닌 경우 다른 이미지에서 사용한 데이터를 기반으로 출력 할 수 있습니까? 또한, 이미지를 사용하지 말고 일반 텍스트 (단폭형 레이아웃의 경우 4 칸 들여 쓰기 - 모두 선택, Ctrl + K를 누르십시오) – trincot
쿼리 및 결과 그림을 업데이트했습니다. "결과 그림 "어떻게 표시하고 싶지만 모든 열의 마지막 행에 대해 작동하지 않는 롤, 나는 또한 null로 0 싶습니다,이 도움이되기를 바랍니다. – troy