需要表值作为列标题 [英] Need Table Values as Column Titles

查看:24
本文介绍了需要表值作为列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张像:

调查结果

SurveyId Int ex. 12
QuestionName Varchar ex. A18a
QuestionValue Int ex. 2

我正在尝试编写一个查询,通过 SurveyId 将 QuestionName 的值设置为水平列.如果某个问题没有条目,则该值将显示为 NULL.结果如下:

I am trying to write a query that would set the values of QuestionName as columns horizontally, by SurveyId. If there is no entry for a certain question, that value would read NULL. The result would look like:

SurveyId | A01 | A02 | A03 | A04...
12 | 1 | 4 | 3 | NULL...
213 | 2 | 5 | NULL | NULL ...

我不知道如何选择问题作为列标题.有没有简单的方法来实现这一点?任何帮助,将不胜感激.

I can't figure out how to select the questions as column titles. Is there an easy way of accomplishing this? Any help would be appreciated.

推荐答案

这基本上一个数据透视表.

This basically is a pivot table.

可以在此处找到有关如何存档的不错的教程:http://www.artfulsoftware.com/infotree/queries.php#78

A nice tutorial on how to archive this can be found here: http://www.artfulsoftware.com/infotree/queries.php#78

我建议您阅读这篇文章并根据您的需求调整此解决方案.

I advise reading this post and adapt this solution to your needs.

这篇关于需要表值作为列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆