feb 510 等.. i希望显示如下 jan feb is作为标题。 jan feb 500 510Hi I have two columns(month,amount). i had enter the datas of the year. i need to show it in row wise. i show u the format like below. i dont know how to construct sql query.table:month Amountjan 500feb 510etc..i want to display like thisjan feb is act as header.jan feb500 510推荐答案SELECT * FROM tablenamePIVOT( sum(amount) FOR month IN ([jan],[feb]))AS somename是的,你可以使用数据透视或案例条件Yes you can using pivot or case conditionSELECT SUM(A.JAN)AS JAN,SUM(A.FEB)AS FEBFROM (SELECT CASE WHEN [month]='jan' THEN amount ELSE 0 END AS JAN,CASE WHEN [month]='feb' THEN amount ELSE 0 END AS FEBFROM dbo.tbl1)AS A只是要添加,我写了一篇文章,解释了所有可能的方法,以及它们如何工作: SQL Wiza rdry Part Seven - PIVOT和任意数据列表 [ ^ ]Just to add, I've written an article that explains all the possible ways to do this, and how they work: SQL Wizardry Part Seven - PIVOT and arbitrary lists of data[^] 这篇关于SQl查询列到行视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 08:53