このクエリは、各エンジニアが時間、日、週、月に分割したテストの合計数を同じテーブル(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
2番目の画像は*希望の*出力ですか、または*現在の出力ですか? *望ましい*出力でない場合は、他の画像で使用したデータに基づいて出力できますか?また、画像は使用しないでください。ただし、平置きテキスト(固定幅の4つのスペースでインデントされています - すべてを選択し、Ctrl + Kを押してください)を入力してください。 – trincot
クエリと結果の画像を更新しました。 "どのように私はそれが表示されますが、すべての列の最後の行のために働いているロールアップは、私も0としてnullを持っていると思いますが、これは助けることを願って – troy