Access中行转列sql语句

select 项目,数量 from (select 项目='总户数',数量=总户数 from 社区居委会资料 union all select 项目='户籍户数',数量=户籍户数 from 社区居委会资料 union all select 项目='户籍人口',数量=户籍人口 from 社区居委会资料 union all select 项目='常住人口',数量=常住人口 from 社区居委会资料 union all select 项目='户在人在数',数量=户在人在数 from 社区居委会资料 union all select 项目='户在人不在数',数量=户在人不在数 from 社区居委会资料 union all select 项目='人在户不在数',数量=人在户不在数 from 社区居委会资料 union all select 项目='流动人口',数量=流动人口 from 社区居委会资料) t

以上sql语句在sql查询分析器中可以执行,但是用到access中的时候就会提示“至少有一个参数未指定”的错误,请各位帮忙看看需要怎样修改。
下面的图片是原数据以及所要实现的结果数据格式。
就是下面这个图片

你确认你的程序可以在sqlserver查询分析器执行?我在SqlServer2005上不能执行
实现起来并不难,需要一些数学函数

select max(case when 项目='总户数' then 数量 else null end) 总户数,
max(case when 项目='户籍户数' then 数量 else null end) 户籍户数,
max(case when 项目='户籍人口' then 数量 else null end) 户籍人口,
max(case when 项目='常住人口' then 数量 else null end) 常住人口,

max(case when 项目='户在人在数' then 数量 else null end) 户在人在数,
max(case when 项目='户在人不在数' then 数量 else null end) 户在人不在数,
max(case when 项目='人在户不在数' then 数量 else null end) 人在户不在数,
max(case when 项目='流动人口' then 数量 else null end) 流动人口
from 社区居委会资料

我没有accsee,没法测试,不过建议你将
项目='户籍人口',数量=户籍人口
改为
'户籍人口' 项目,户籍人口 数量
试试看,异次类推,所有的都改成我的这种写法,你用的那种事专用语法,而不是通用语法
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜