sql语言表示

表为(SNO,GNO,QTY 分别为商店号,商品号,销售量)
SNO GNO QTY
S01 G01 500
S01 G02 100
S02 G01 200
S03 G03 500
S03 G01 450
S04 G07 560
S06 G06 100
S07 G07 152

查询平均销售量最高的商品号,Sql语言怎么写?
谢谢蓝带二锅头的回答.
不过,你这个本身也是错的,可能是你高级语言的习惯带进来了.我在想最主要还是有个平均.

谢谢ieool发短信给我,可是我给不了你分了.

第1个回答  2007-04-21
create database shopping
on primary
(
name = 'shopdata',
filename = 'c:\shop.mdf',
size = 10mb,
maxsize = 100mb,
filegrowth = 1mb
)
log on
(
name = 'shoplog',
filename = 'c:\shop.log',
size = 10mb,
maxsize = 100mb,
filegrowth = 1mb
)
go
create table shoptable
(
sno varchar(10),
gno varchar(10),
qty int
)
go
insert into shoptable values('s01','g01','500')
go
insert into shoptable values('s01','g02','100')
go
insert into shoptable values('s02','g01','200')
go
insert into shoptable values('s03','g03','500')
go
insert into shoptable values('s03','g01','450')
go
insert into shoptable values('s04','g07','560')
go
insert into shoptable values('s06','g06','100')
go
insert into shoptable values('s07','g07','152')
go
/*查询平均销售量最高的商品号*/
select top 1 gno from shoptable where qty > (select avg(qty) from shoptable) order by qty desc
第2个回答  2007-04-21
不知这样行不行

SELECT top(1) [GNO],AVG(QTY) as Avg_QTY
FROM [Table_1] group by GNO order by Avg_QTY DESC本回答被提问者采纳
第3个回答  2007-04-21
select top 1 gno,avg(qty)a from 表 group by gno order by a desc
第4个回答  2007-04-21
select GNO from tablename where QTY=max(QTY)
相似回答