第一个查询是我需要的 15 英里半径范围内公司的所有信息。
SELECT DISTINCT CI.co,
CI.name,
CI.address1,
CI.address2,
CI.city,
CI.state,
CI.zip,
CI.contact1,
CI.contact1email,
CI.contact2,
CI.contact2email,
CI.contact3,
contact3email,
Count(EI.id) AS ActiveEE
FROM cinfo CI
INNER JOIN einfo EI
ON CI.co = EI.co
WHERE NOT CI.co IN (SELECT co
FROM scompanysetdetail
WHERE companyset = 'REF-GCohen')
AND enddate IS NULL
AND EI.empstatus = 'A'
AND CI.zip IN ( *zip codes for the 15 mile radius* )
GROUP BY CI.co,
CI.name,
CI.address1,
CI.address2,
CI.city,
CI.state,
CI.zip,
CI.contact1,
CI.contact1email,
CI.contact2,
CI.contact2email,
CI.contact3,
CI.contact3email
第二个查询为我提供了按公司划分的前 10 名带薪员工
WITH cterownum
AS (SELECT co,
id,
ename,
title,
hiredate,
salary,
Dense_rank()
OVER(
partition BY co
ORDER BY salary DESC) AS RowNum
FROM cps_wss_emplist)
SELECT *
FROM cterownum
WHERE rownum <= 10
ORDER BY co,
rownum ASC
如何将这两个查询合并为一个?