$sql = " select personid,std_name,f_name,sum(case when em_c=answer then 1 else 0 end) as cnt ";
$sql .= " from trans as a inner join trans_detail as b on a.tid=b.tid ";
$sql .= " group by personid,std_name,f_name ";
$sql .= " order by personid desc ";
SELECT
MAX(x.`cnt`)
FROM (
SELECT
`personid`,
`std_name`,
`f_name`,
SUM(CASE
WHEN `em_c` = 'answer' THEN 1
ELSE 0
END) AS `cnt`
FROM
`trans` a
INNER JOIN
`trans_detail` b ON a.`tid` = b.`tid`
GROUP BY
`personid`,
`std_name`,
`f_name`
ORDER BY
`personid` DESC) x
SELECT
MAX(x.`cnt`)
FROM (
SELECT
`personid`,
`std_name`,
`f_name`,
SUM(CASE
WHEN `em_c` = 'answer' THEN 1
ELSE 0
END) AS `cnt`
FROM
`trans` a
INNER JOIN
`trans_detail` b ON a.`tid` = b.`tid`
GROUP BY
`personid`,
`std_name`,
`f_name`) x