我创建了下表
create table Interiors(
no integer,
name varchar,
type varchar,
dateofstock datetime,
price decimal(6,3),
discount numeric(6,2))我想解决这两个问题。
我为每一个研究写了下面的stmt。
。
我得到了相同的错误,因为这两个‘类型不是一个聚合的乐趣。或者它没有组按’子句。我应该做些什么来解决这些问题。
发布于 2011-03-01 11:06:26
按“婴儿床”分组。
你不能按某物的名称分组,你必须按列名分组。例如:
select type, sum(price), avg(discount) from Interiors group by type
or
select type, sum(price), avg(discount) from Interiors where type = 'baby cot' group by type发布于 2011-03-01 11:07:33
您需要按字段名而不是内容进行分组。如果您希望只包括类型为“婴儿床”的数据,则应在where子句中包含该数据。例如..。
SELECT
type,
SUM(price) AS "sum",
AVG(price) AS "avg",
MAX(price) AS "max",
MIN(price) AS "min"
FROM
Interiors
WHERE
type = 'baby cot'
GROUP BY
type发布于 2011-03-01 11:08:32
阅读以下内容:http://msdn.microsoft.com/en-us/library/aa258901%28v=sql.80%29.aspx
它是用于Server聚合函数的MSDN条目。有很多例子,包括你想要达到的目标。
https://stackoverflow.com/questions/5153576
复制相似问题