Home > Database > Mysql Tutorial > body text

数据透视

WBOY
Release: 2016-06-07 14:57:47
Original
1278 people have browsed it

对数据集进行透视 无 DECLARE @sql NVARCHAR(2000)SELECT @sql=ISNULL(@sql+',','')+'['+FEEDATE+']' FROM TEMPTB GROUP BY FEEDATE PRINT @sql--注意,pivot透视中的in后面的条件中,只能是以字符开始,如:汉字、字母;--上面的FEEDATE即使设置为varchar类型,

对数据集进行透视
DECLARE
    @sql NVARCHAR(2000)
SELECT @sql=ISNULL(@sql+',','')+'['+FEEDATE+']'  FROM TEMPTB GROUP BY FEEDATE    
PRINT @sql
--注意,pivot透视中的in后面的条件中,只能是以字符开始,如:汉字、字母;
--上面的FEEDATE即使设置为varchar类型,但如果其内容为20121101,1,2等数字,放在下面的IN当中仍然会出错
--所以,在数字外面包括了一层[FEEDATE]
SET @sql='SELECT * FROM TEMPTB PIVOT(MAX(TOTALFEE) FOR FEEDATE IN('+@sql+'))A'
EXEC(@sql)
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!