我有一个表,里面存了些销售记录,其中包括 货物名称 text,货物数量 int,记录中存在货物名称相同的行,我想统计每种货物的总数量,
语句为
select 货物名称,sum(货物数量) from sell group by (cast(货物名称 as varchar(8000)))
提示说
服务器: 消息 8120,级别 16,状态 1,行 1
列 'sell.货物名称' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
该怎么写?
语句为
select 货物名称,sum(货物数量) from sell group by (cast(货物名称 as varchar(8000)))
提示说
服务器: 消息 8120,级别 16,状态 1,行 1
列 'sell.货物名称' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
该怎么写?
from sell
group by cast(货物名称 as varchar(8000))
from sell
group by cast(货物名称 as varchar(8000))
(select (cast(货物名称 as varchar(8000))) as 货物名称
,货物数量 from sell) t
group by 货物名称
from sell
group by cast(货物名称 as varchar(8000))