使用SELECT创建逗号分隔列表 [英] Create a Comma Delimited List Using SELECT
本文介绍了使用SELECT创建逗号分隔列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有查询
i have query
select [1] AnalysisCount,[2] DietitianCount,[3] DoctorCount ,AppointmentDate
from
(
select AppointmentDate ,AppointmentDate as dd, AppointmentTypeID from dbo.Appointment
) ss
pivot (count(dd) For AppointmentTypeID in ([1],[2],[3]) )
as pvt
outed out put
Date AnalysisCount,DietitianCount,DoctorCount
即计数由昏迷分隔为单列
PLZ help
ineed out put as
Date AnalysisCount,DietitianCount,DoctorCount
ie count is seperated by coma as single column
PLZ help
推荐答案
尝试
http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/ [<一个href =http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/target =_ blanktitle =New Window> ^ ]
https://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/ [ ^ 一>]
示例查询:您可以尝试这种方法:
Example Query: You May Try this method:
create table piv (number int primary key,marks decimal(18,2))
insert into piv(number,marks) values (1,24),(2,154),(4,345),(6,234.56),(8,456.90)
select * from piv
select number,AVG(marks) as Average from piv group by number
--pivot
select 'marks'as number,[1]avv,[2]qq,[4]qq,[6]qq,[8]q from (select * from piv)as sourcetable
pivot(avg(marks) for number in ([1],[2],[3],[4],[5],[6],[7],[8]))as pivottable
这篇关于使用SELECT创建逗号分隔列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文