如何组合加入这两个表?
SELECT job_category.JobCategoryId, job_category.JobCategoryName, count(job_position.JobCategoryId)
AS AvailableCategories
FROM job_position
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName
(SELECT job_category.JobCategoryId, job_category.JobCategoryName, count(job_position.ContactId) AS AllocatedJobs
FROM job_position
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
WHERE job_position.ContactId > 0
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName)
由于
答案 0 :(得分:0)
我认为应该是这样的
Select T1.JobCategoryId, T1.JobCategoryName, T1.AvailableCategories, T2.AllocatedJobs
FROM
(SELECT job_category.JobCategoryId as JobCategoryId, job_category.JobCategoryName as JobCategoryName, count(job_position.JobCategoryId)
AS AvailableCategories
FROM job_position
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName) as T1
INNER JOIN
((SELECT job_category.JobCategoryId as T2JobCategoryId, job_category.JobCategoryName as T2JobCategoryName, count(job_position.ContactId) AS AllocatedJobs
FROM job_position
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
WHERE job_position.ContactId > 0
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName)) as T2
ON T1.JobCategoryId = T2.T2JobCategoryId