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.