$SQL = "SELECT Name, JobType,SUM(Total pages) AS Total FROM test WHERE JobType='COPY' OR JobType='PRINT'
GROUP BY Name,JobType";
$rs = mysql_query($SQL);
$rw = mysql_fetch_array($rs);
หากต้องการให้แสดงผลออกมาแบบนี้
name copy total print total
------------------------------------
นายเอ 7 5
select t1.name,t2.copy,t3.print from test t1
left join (
select sum(totalpages) as copy,name from test where jobtype='COPY' group by name,jobtype limit 1
) as t2 on t1.name=t2.name
left join (
select sum(totalpages) as print,name from test where jobtype='PRINT' group by name,jobtype limit 1
) as t3 on t1.name=t3.name