我的查询有问题。我有 2 张桌子:
表 1 是AutoCompany
它有字段company
和CodeCar
. CodeCar
可以是 3 或 4,具体取决于公司拥有的汽车类型。
表 1:汽车公司
company| CodeCar|
jora 3
jora 4
jora 3
ghita 3
ghita 3
ghita 4
gheorghe 4
gheorghe 3
gheorghe 3
表 2CodeCarCompanies
有代码:
car | codeCar
mers 3
vW 4
我需要选择具有 2 codeCar
s 出现次数的公司,结果如下:
company | MERS| VW
jora 2 1
ghita 2 1
gheorghe 2 1
到目前为止我的尝试:
SELECT COUNT(dbo.AutoComany) AS MERS, dbo.Company, COUNT(dbo.AutoComany.
[CodeCar]) AS VW,
FROM dbo.AutoComany FULL OUTER JOIN
dbo.AutoComany ON dbo.АВТОМОБ.КодПредпр = AutoCompany.company
WHERE (dbo.CodeCarComapnies.[CodeCar] = 3)
GROUP BY dbo..company, dbo.CodeCarComapnies.[CodeCar]
HAVING (dbo.CodeCarComapnies.[CodeCar] = 4)