M*********e 发帖数: 190 | 1 task table is the original table.
SELECT v1.*,
v2.total
FROM task v1
LEFT OUTER JOIN
(SELECT t1.*,
t2.total
FROM task t1,
(SELECT taskname,
taskstatus,
COUNT(*) AS total
FROM task
GROUP BY taskname,
taskstatus
) t2
WHERE t1.taskname=t2.taskname
AND t1.taskstatus=t2.taskstatus
AND t1.taskid IN
(SELECT MAX(taskid) FROM task GROUP BY taskname, taskstatus
)
) v2
ON v1.taskid=v2.taskid
ORDER BY v1.taskid; |
|