Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i created this view to calculate the total stocks of every item in every store as :

CREATE OR REPLACE VIEW `view_items_stocks_smallest_unit_prices_noserials` as
							  SELECT items.stitems_ID,
							  items.stitems_Status,
							  items.stitems_Name,
							  items.stitems_Type,
							  items.stitems_Code,
                              unitsdet.DetunitID,
							  unitsnamesdet.UnitName,
                              ca.NOSStoreID,
							  COALESCE(ca.Amount, 0) AS Stock,
                              ca.MaxPurchasesPrice,
                              ca.purchases_price_withoutDiscOrXtra
					   FROM st_items items
					   LEFT JOIN (SELECT sns.stitems_ID,
                                         sns.StoreID AS NOSStoreID,
										 SUM(sns.StockQnty) AS Amount,
                                         MIN(sns.purchases_price) AS MaxPurchasesPrice,
                                         MAX(sns.purchases_price_withoutDiscOrXtra) AS purchases_price_withoutDiscOrXtra
								  FROM stock_noserials sns
								  GROUP BY sns.stitems_ID , NOSStoreID) ca
					   ON ca.stitems_ID = items.stitems_ID
                       LEFT JOIN (SELECT units.stitemsu_ID as DetunitID,
										 units.stitemsu_UnitName as unitID,
                                         units.stitems_ID as ItemIDa
								  FROM st_items_units units
								  WHERE units.stitemsu_UnitNum = 1
								  GROUP BY units.stitemsu_ID) unitsdet
					   ON items.stitems_ID = ItemIDa
                       LEFT JOIN (SELECT unitsnames.ID as UnameID,
										 unitsnames.Unit as UnitName
								  FROM st_units_name unitsnames
								  GROUP BY unitsnames.ID) unitsnamesdet
					   ON unitsdet.unitID = UnameID
					GROUP BY items.stitems_ID, ca.NOSStoreID;



i try now to select from it using EF6 as :

var StocksData = DB1.view_items_stocks_smallest_unit_prices_noserials.Where(u => u.stitems_ID == itemID && u.NOSStoreID == storeID);
                            int sstock = Convert.ToInt32( StocksData.FirstOrDefault().Stock);


but this error appear :
expression #6 select list is not in group by clause and contains nonaggregated column 'unitsdet.DetunitID' which is not functionally depond on colmuns group by clause this is comptible with Sql_mode = only_full_group by

What I have tried:

- i deleted this line
GROUP BY units.stitemsu_ID
but same error appear.
- i replaced this line
GROUP BY sns.stitems_ID , NOSStoreID
with this line
GROUP BY sns.stitems_ID
. and the error disappeared but i need to group the results with store id also.
Posted
Updated 26-Feb-19 4:48am

1 solution

 
Share this answer
 
Comments
Golden Basim 26-Feb-19 12:26pm    
thanks for comment ..
please help me to understatnt that .. i should to group with all colmuns ? as :
GROUP BY items.stitems_ID, ca.NOSStoreID,unitsdet.DetunitID,ca.Amount;
OriginalGriff 26-Feb-19 12:30pm    
Follow the link and read it - you need to understand what GROUP BY does.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900