我尝试了这个查询但没有打算正确的输出 [英] I tried this query but not geeting the correct output

查看:54
本文介绍了我尝试了这个查询但没有打算正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ms访问数据库中我的查询如下



My query as follows in ms access data base

TRANSFORM First(Tb_SCh_TIme_Table.Faculty_Code) AS a
SELECT Tb_SCh_TIme_Table.Sch_Date, Tb_SCh_TIme_Table.Course
FROM Tb_SCh_TIme_Table
GROUP BY Tb_SCh_TIme_Table.Sch_Date, Tb_SCh_TIme_Table.Course,Tb_SCh_TIme_Table.Faculty_Code
PIVOT Tb_SCh_TIme_Table.Session



输出如下;




Output as follows;

Sch_Date    Course    1      2     3
12/01/2013  AFF       GS
12/01/2013  AFF       NR
13/01/2013  TFC                    GS
13/01/2013  TFC       VB    VB





从上面的输出我想要最终输出如下;



From the above output I want the final output as follows;

Sch_Date    Course    1         2     3
12/01/2013  AFF       GS,NR
13/01/2013  TFC                       GS
13/01/2013  TFC       VB       VB



使用我的上述查询如何获得输出。





我该怎么办?请帮帮我。



代码块添加[/编辑]


Using my above query how to get the output.


How can I do? Please help me.

Code block added[/Edit]

推荐答案

一个非常简单方便的解决方案...



试试这个



HTTP ://tejasnshah.wordpress.com/2009/02/28/sql-server-get-column-values-as-comma-seperated-list-using-xml-path-instead-of-udfs-using-sql-coalesce / [ ^ ]
A very simple and handy solution ...

Try this

http://tejasnshah.wordpress.com/2009/02/28/sql-server-get-column-values-as-comma-seperated-list-using-xml-path-instead-of-udfs-using-sql-coalesce/[^]




尝试使用以下查询

Hi,
Try with the below Query
SELECT t1.Sch_Date,t1.Session,t1.Course,
       Faculty_Code =REPLACE( (SELECT Faculty_Code AS [data()]
           FROM [tb_SchTime_Table] t2
          WHERE t2.Sch_Date = t1.Sch_Date and t2.Course=t1.Course
            FOR XML PATH('')
            ), ' ', ',')
      FROM [tb_SchTime_Table] t1
      GROUP BY Sch_Date,Course,Session ;





最好的问候

Muthuraja



Best Regards
Muthuraja


这篇关于我尝试了这个查询但没有打算正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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