我想从一个表中检索数据,但数据基于条件。
所以现在我已将count部分添加到我的查询中,但它没有执行,并且发生了以下错误:
列'DailyStockHistory.Stc_Item_Desc'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中
查询是:
Select
*
From
(
Select
dsh.Stc_Item_Desc, dsh.Imported_Date, dsh.Store_ID, dsh.Quantity_On_Hand,Count(inv.Sim_Network_Type) counterr
From DailyStockHistory dsh,
Temp_DailyInventory inv
Where Stc_Item_Desc = 'SAWA/QuickNet prepaid triosim'
And dsh.Store_ID Like 'S%'
And (Imported_Date = '3-15-2017' Or Imported_Date = '3-22-2017')
) AS Data
PIVOT
(
SUM(Quantity_On_Hand)
FOR Imported_Date IN ([3-15-2017],[3-22-2017])
) AS PIVOTData