Sql选择查询 [英] Sql Select Query

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

问题描述

您好,



我的桌子上有这样的记录 -







Particluar ------------------------------------ -Amount



消费税12%---------------------------- 2775.00

Edu CESS 2%-------------------------------- 56.00

HR Edu CESS 1%---------------------------- 28.00

Sale CST 2% --------------------------------- 520.00



我想从选择查询中得到以下内容



消费税12%---- Edu CESS 2%---- HR Edu CESS 1% - - 销售CST 2%

2775.00 ----------------- 56.00 ------------- 28.00 --- ---------- 520.00





如果可能的话请回复我的紧急情况......
提前使用Thanx ....

Hello,

I have a table that have records like this -



Particluar-------------------------------------Amount

Excise Duty 12 % ---------------------------- 2775.00
Edu CESS 2% -------------------------------- 56.00
HR Edu CESS 1% ---------------------------- 28.00
Sale CST 2% --------------------------------- 520.00

and I would like to get the following from select query

Excise Duty 12 % ---- Edu CESS 2% ---- HR Edu CESS 1% ---- Sale CST 2%
2775.00 ----------------- 56.00 ------------- 28.00 ------------- 520.00


If it possible then please reply me its urgent...
Thanx in advance....

推荐答案

您可以尝试这样: -





You can try like this:-


declare @columns varchar(max)
declare @convert varchar(max)
select @columns =stuff((select '],[' + particular from tblName order by '],['
                                   + convert(varchar(max),points) desc
                                     for xml path('')),1,2,'') + ']'

--Select @columns column

 set @convert= 'select * from (select * from tblName) contributors
                            pivot (sum(points) for particulars in (' +@Columns + ')) as                               pivottbl'


--select @convert
execute (@convert)


PIVOT可能有助于解决您的问题。请试试。
PIVOT may help for your problem. Please try it.


这篇关于Sql选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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