如何从两个表中获取数据?

时间:2012-09-12 13:14:19

标签: sql-server sql-server-2008

我在SQL Server中有两个表

tbl_posting_job_info

enter image description here

tbl_jobseeker_applied_job

enter image description here

在相应表格中的这两个表job_posting_idapplied_job_id主键

tbl_posting_job_info字段中job_posting_idtbl_jobseeker_applied_job中引用为FK

所以,我的问题是如何获取前company_id最常适用的前25 jobseeker

感谢。

1 个答案:

答案 0 :(得分:1)

SELECT TOP 25 COUNT(b.applied_job_id), a.CompanyID
FROM tbl_posting_job_info a INNER JOIN
tbl_jobseeker_applied_job b ON a.job_posting_id = b.job_posting_id
GROUP BY a.CompanyID
ORDER BY Count(b.applied_job_id) DESC