There is a table MovementGoods, in it the fields Date_, Count_. The first field of the date type, the second numeric. I am writing this query:

SELECT Sum(MovementGoods.Count_) AS [SumCount] FROM MovementGoods GROUP BY [SumCount]; 

It would seem easier nowhere, but nevertheless, it does not work. There is a summation of numeric values ​​and grouping by SumCount field. What is the problem?

  • And what exactly should make your request. Calculate the amount of MovementGoods.Count_ by all MovementGoods (get one value for the whole table) + group by this one value? What do you expect to see as a result? - PashaPash
  • @PashaPash, yes, just print the sum of the numbers distributed on specific dates. However, the query does not work and requires you to enter the SumCount value. This is the simplest option, where the aggregate function SUM, at the end of the query is indicated grouping by this field. What is the problem? Interestingly, does this work? - IntegralAL
  • If you just need the amount - do not do the grouping, and the amount will be calculated over the entire table. If you need an amount by date - group by date field. - PashaPash

1 answer 1

This is an invalid request. The order of the SELECT is:

 FROM WHERE GROUP BY HAVING SELECT ORDER BY 

Thus, at the time when GROUP BY is SumCount does not exist yet. Need to

 SELECT Sum(MovementGoods.Count_) AS [SumCount] FROM MovementGoods GROUP BY какоето поле; 
  • Yes, that's exactly what I wanted to know. Thank you for the order of the request. This is important - IntegralAL