The GROUP BY clause will gather all of the rows together that contain data in the specified columns (here the GroupBy operation is performed on columns L.ItemNo, L.Lot, L.Description and L.Quantity) and will allow aggregate functions to be performed on the one or more columns( Here the aggregation is done on L.PostingDate).
So each record with a distinct combination of the group by columns i.e L.ItemNo, L.Lot, L.Description and L.Quantity will come along with the aggregation on the duplicate combinations of it. For instance, considering your example: -
Let us assume that you have below records in your table:-
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-05-27 I789 Apple 45 L789
I789 LOT789 2021-05-29 I789 Apple 38 L789
I789 LOT789 2021-05-25 I789 Apple 45 L789
I789 LOT789 2021-05-28 I789 Apple 45 L789
I789 LOT789 2021-06-01 I789 Apple 38. L789
I789 LOT555 2021-06-01 I789 Apple 11. L555
So when you do a group by on Identifier, ItemNo, Description, Quantity and Lot, SQL will understand that you want to do a logical grouping of these columns and it will divide data and understand it as below:-
-- Group 1
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-05-27 I789 Apple 45 L789
I789 LOT789 2021-05-25 I789 Apple 45 L789
I789 LOT789 2021-05-28 I789 Apple 45 L789
-- Group 2
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-05-29 I789 Apple 38 L789
I789 LOT789 2021-06-01 I789 Apple 38. L789
-- Group 3
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT555 2021-06-01 I789 Apple 11. L555
Now when you have any aggregate function run on these records on some particular column, it will try to run the aggregate function for each logical grouping it has encountered ( There are 3 in this case as we saw above)
So in our case, the aggregate function is Max(L.PostingDate) which will select the record with the maximum date for each group it has identified till now like below:-
-- Group 1
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-05-28 I789 Apple 45 L789
-- Group 2
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-06-01 I789 Apple 38. L789
-- Group 3
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT555 2021-06-01 I789 Apple 11. L555
And now finally it combines all records and shows the result as below:-
-- Final Ouput
Identifier PostingDate ItemNo Description Quantity Lot
I789 LOT789 2021-05-28 I789 Apple 45 L789
I789 LOT789 2021-06-01 I789 Apple 38. L789
I789 LOT555 2021-06-01 I789 Apple 11. L555
This is how group by functions, so in your case, if you don't want the group by to happen on quantity columns, you can simply remove it from select query as well as groupBy, or else if you include the quantity column to group by it will keep printing the records with the distinct column combination.