T-SQL aggregate function Logical error

Ok I have a data table containing the duplicate Reciept numbers and the transaction value for each record, I just need to list the amount for each unique Reciept number, this is obviously a simple problem, but I am missing something.

Any help is multifaceted

SELECT Gf_Receipt_number AS Reciept,
       SUM (Gf_Amount) AS Total
  FROM [TestP].[dbo].[Gf]
 WHERE Gf_Receipt_number IS NOT NULL
 GROUP BY Gf_Amount

      

It probably helps to mention the error I'm getting:

The column "TestP.dbo.Gf.Gf_Receipt_number" is not valid in the picklist because it is not contained in either an aggregate function or a GROUP BY clause.

+2


a source to share


3 answers


You need to group by Gf_Receipt_number instead of Gf_Amount



The GROUP BY clause specifies which columns are used to distinguish one group of records from another, while the column used in aggregate functions (for example, SUM (Gf_Amount)) determines how other columns in those records are combined into one value.

+7


a source


Instead, you should select GROUP BY Gf_Receipt_number.



+1


a source


You will need to put the GF_Receipt_number in your group to clear the error. Group by refrence

+1


a source







All Articles