我的查询向我提供了项目(eqmt)的结果
但是我需要按类别(单位)分组的每日总数,我正在调查内部联接,但这是我不知道的
这是总装备及其工作的查询。
SELECT hist_eqmtlist.unit,
hist_statusevents.eqmt,
hist_exproot.shiftdate,
sum(case when hist_statusevents.category =1 then (hist_statusevents.duration/3600) else 0 end) as '1',
sum(case when hist_statusevents.category =2 then (hist_statusevents.duration/3600) else 0 end) as '2',
sum(case when hist_statusevents.category =3 then (hist_statusevents.duration/3600) else 0 end) as '3',
sum(case when hist_statusevents.category =4 then (hist_statusevents.duration/3600) else 0 end) as '4',
sum(case when hist_statusevents.category =5 then (hist_statusevents.duration/3600) else 0 end) as '5',
sum(case when hist_statusevents.category =6 then (hist_statusevents.duration/3600) else 0 end) as '6'
FROM hist_eqmtlist,hist_exproot,hist_statusevents
WHERE hist_exproot.shiftindex = hist_statusevents.shiftindex And hist_statusevents.shiftindex = hist_eqmtlist.shiftindex And hist_statusevents.eqmt = hist_eqmtlist.eqmtid
GROUP BY hist_statusevents.eqmt, hist_exproot.shiftdate, hist_eqmtlist.unit
ORDER BY hist_exproot.shiftdate,hist_statusevents.eqmt
这是相同的查询,但结果是单位(类别)
SELECT hist_eqmtlist.unit,
hist_exproot.shiftdate,
sum(case when hist_statusevents.category =1 then (hist_statusevents.duration/3600) else 0 end) as '1',
sum(case when hist_statusevents.category =2 then (hist_statusevents.duration/3600) else 0 end) as '2',
sum(case when hist_statusevents.category =3 then (hist_statusevents.duration/3600) else 0 end) as '3',
sum(case when hist_statusevents.category =4 then (hist_statusevents.duration/3600) else 0 end) as '4',
sum(case when hist_statusevents.category =5 then (hist_statusevents.duration/3600) else 0 end) as '5',
sum(case when hist_statusevents.category =6 then (hist_statusevents.duration/3600) else 0 end) as '6'
FROM hist_eqmtlist,hist_exproot,hist_statusevents
WHERE hist_exproot.shiftindex = hist_statusevents.shiftindex And hist_statusevents.shiftindex = hist_eqmtlist.shiftindex And hist_statusevents.eqmt = hist_eqmtlist.eqmtid
GROUP BY hist_exproot.shiftdate, hist_eqmtlist.unit
ORDER BY hist_exproot.shiftdate
为什么我需要这个?
因为我需要把它放在我的php上然后放入嵌套表