@ Стивен C. Похоже, вам нужно использовать UNION
, чтобы соединить результаты двух запросов.
Вот как вы это сделаете:
SELECT nama_account,
jabatan,
nama_tp,
jam_berangkat,
jam_pulang,
jumhar,
SUM(jum) AS jumTotal
FROM (
SELECT a.nama_account,
a.jabatan,
b.nama_tp,
a.jam_berangkat,
a.jam_pulang,
(SUM(IF((jam_awal < jam_berangkat) AND (jam_akhir > jam_pulang),'1','0'))+dinas+dinastp) jum,
DATEDIFF('$tgl2','$tgl1')+1 jumhar
FROM t_account a
LEFT JOIN t_tp b ON a.tp_ID=b.ID
LEFT JOIN t_user c ON a.userCode=c.userCode
LEFT JOIN (
SELECT DATE(`tanggal`) tgl,
phoneNumber,
MIN(TIME( tanggal)) jam_awal,
MAX(TIME( tanggal)) jam_akhir,
SUM(IF(saran = '1234','1','0')) dinas,
SUM(IF(saran = '4321','1','0')) dinastp
FROM t_report
WHERE ( tanggal BETWEEN '$tgl1 00:00:00' AND '$tgl2 23:59:59' )
GROUP BY DATE(tanggal),phoneNumber
) tlis
ON tlis.phoneNumber = a.`imei_number`
WHERE a.grup_ID = '$grup'
$queryIf
AND (c.user_status !='3' AND c.user_status != '999')
GROUP BY a.`imei_number`
ORDER BY b.nama_tp,a.jabatan
UNION
SELECT a.nama_account,
a.jabatan,
b.nama_tp,
a.jam_berangkat,
a.jam_pulang,
(SUM(IF((jam_awal < jam_berangkat) AND (jam_akhir > '$jampulang_sabtu'),'1','0'))+dinas+dinastp) jum,
DATEDIFF('$tgl2','$tgl1')+1 jumhar
FROM t_account a
LEFT JOIN t_tp b ON a.tp_ID=b.ID
LEFT JOIN t_user c ON a.userCode=c.userCode
LEFT JOIN (
SELECT DATE(`tanggal`) tgl,
phoneNumber,
MIN(TIME( tanggal)) jam_awal,
MAX(TIME( tanggal)) jam_akhir,
SUM(IF(saran = '1234','1','0')) dinas,
SUM(IF(saran = '4321','1','0')) dinastp
FROM t_report
WHERE ( tanggal BETWEEN '$tgl1 00:00:00' AND '$tgl2 23:59:59') AND DAYNAME(tanggal)='Saturday'
GROUP BY DATE(tanggal),phoneNumber
) tlis
ON tlis.phoneNumber = a.`imei_number`
WHERE a.grup_ID = '$grup'
$queryIf
AND (c.user_status !='3' AND c.user_status != '999')
GROUP BY a.`imei_number`
ORDER BY b.nama_tp,a.jabatan
) AS derivedTable
GROUP BY nama_account,
jabatan,
nama_tp,
jam_berangkat,
jam_pulang,
jumhar;
Вот вам go: общая сумма значений jum
из 2 запросов.
Надеюсь, это поможет.