如 表1
名称 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11 月 12 月
a 10 20 10 40 50 60 70 80 90 100 10 20
....求表1中数据列中
数据最大字段列的值 最小字段列的值,平均12个月字段值结果
名称 最大值 最小值 平均值
a 100 10 (10+20+10+40+50+60+70+80+90+100+10+20)/12=46.67
求sql语句
名称 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11 月 12 月
a 10 20 10 40 50 60 70 80 90 100 10 20
....求表1中数据列中
数据最大字段列的值 最小字段列的值,平均12个月字段值结果
名称 最大值 最小值 平均值
a 100 10 (10+20+10+40+50+60+70+80+90+100+10+20)/12=46.67
求sql语句
select 名称,max([Value]),min([Value]),avg([Value])
from
(
select 名称,[1月] as [Value] from tablename
union all
select 名称,[2月] as [Value] from tablename
union all
select 名称,[3月] as [Value] from tablename
union all
select 名称,[4月] as [Value] from tablename
union all
select 名称,[5月] as [Value] from tablename
union all
select 名称,[6月] as [Value] from tablename
union all
select 名称,[7月] as [Value] from tablename
union all
select 名称,[8月] as [Value] from tablename
union all
select 名称,[9月] as [Value] from tablename
union all
select 名称,[10月] as [Value] from tablename
union all
select 名称,[11月] as [Value] from tablename
union all
select 名称,[12月] as [Value] from tablename
)T
group by 名称
Select a.名称,
max(b.1月,b.2月,b.3月,b.4月,b.5月,b.6月,b.7月,b.8月,b.9月,b.10月,b.11 月,b.12 月),
mmin(b.1月,b.2月,b.3月,b.4月,b.5月,b.6月,b.7月,b.8月,b.9月,b.10月,b.11 月,b.12 月),
avg(b.1月,b.2月,b.3月,b.4月,b.5月,b.6月,b.7月,b.8月,b.9月,b.10月,b.11 月,b.12 月)
from 表1 a,表1 b
where a.名称=b.名称
order by a.名称没测试,自己试一下。
名称 月份 数量
a 1月 10
........再用交叉报表方法也可以得出LZ的格式,但这个表结构要完成楼主的查询不就更好?