0
有一个小的MySql问题我希望有人可以看看。MySql计数从其他表作为连接并添加到结果的每一行
当前的SQL:
SELECT IFNULL(ua.total, 0) applications,
users_applications.job_id as job_id,
users.*
FROM users_applications
LEFT OUTER JOIN users
on (users_applications.user_id = users.id)
LEFT OUTER JOIN (
SELECT COUNT(*) total, job_id, id
FROM users_applications
GROUP BY job_id) AS ua
ON (users_applications.id = ua.id)
这是伟大的,它的返回是这样的:
applications | job_id | user_id |
-------------------------------
3 | 1001 | 1001 |
0 | 1001 | 1002 |
0 | 1001 | 1003 |
1 | 1003 | 1004 |
1 | 1003 | 1005 |
0 | 1004 | 1006 |
虽然该作业它只是做它的第一行计数的应用程序的数量,我希望它出现在每一行中,而不是现在的后续行中的0。
非常感谢
因此,这意味着job_id的所有记录都有'3个应用程序'? – 2012-08-15 16:55:58