所以这里是上下文:开发一个 ASP.NET MVC 4 web 应用程序,我在我的数据库中有一个表ProductAllocations,它由两个外键组成:一个来自我的表Products,另一个来自表Persons。我有另一个表Vehicles包含表Products的外键
我想选择按产品分组的分配及其信息(一个产品可以分配多次)。这是我的存储过程:
ALTER PROCEDURE GetAllVehicles
AS
BEGIN
SET NOCOUNT ON
SELECT
p.FirstName,
p.LastName,
pa.EndDate,
pr.PurchaseDate,
pr.SerialNumber,
pr.CatalogPrice,
v.PlateNumber,
v.FirstCirculationDate,
V.FirstDrivingTax,
v.UsualDrivingTax
FROM bm_ProductAllocations AS pa
INNER JOIN bm_Persons AS p ON pa.Id_Person = p.Id_Person
INNER JOIN bm_Products AS pr ON pa.Id_Product = pr.Id_Product
INNER JOIN bm_Vehicles AS v ON pr.Id_Product = v.Id_Product
GROUP BY pa.Id_Product
END
但是,Group By 子句正在生成错误:Column 'bm_Persons.FirstName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
我正在使用 Visual Studio 2010。
我是 SQL 新手,所以我不知道发生了什么。