SQL查询帮助. [英] Help with SQL query.

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

问题描述

我的数据格式如下.


帐户业务行金额
ABC Ltd. PIM 1000
IJK Ltd. PAM 2000
XYZ Ltd. PAM 3000
PQR Ltd.PAM 4000
ABC Ltd. PAM 4000
荷航有限公司PAM 5000
UVW Ltd. PAM 3000
EFG Ltd. PAM 2000
ABC Ltd. Inst 3000
SFX Ltd. PAM 1000
XYZ Ltd. Inst 3000
PQR Ltd. Inst 4500
PQR Ltd. PIM 1500

我需要以下格式的报告:


帐户PIM PAM金额
PQR Ltd.1500 4000 4500 10000
ABC Ltd.1000 4000 3000 8000
XYZ Ltd.0 3000 3000 6000

即排名前三的帐户,其中各业务行的金额显示在各列中,并按金额的总和以降序排列.

任何帮助将不胜感激,
Aakar.






编辑Abuse

I have my data in the below format.


Account Business Line Amount
ABC Ltd. PIM 1000
IJK Ltd. PAM 2000
XYZ Ltd. PAM 3000
PQR Ltd. PAM 4000
ABC Ltd. PAM 4000
KLM Ltd. PAM 5000
UVW Ltd. PAM 3000
EFG Ltd. PAM 2000
ABC Ltd. Inst 3000
SFX Ltd. PAM 1000
XYZ Ltd. Inst 3000
PQR Ltd. Inst 4500
PQR Ltd. PIM 1500

I need the report in the format below :


Account PIM PAM Inst Amount
PQR Ltd. 1500 4000 4500 10000
ABC Ltd. 1000 4000 3000 8000
XYZ Ltd. 0 3000 3000 6000

i.e. the Top 3 accounts with the individual business line amounts shown in the columns ordered by the sum of the amounts in descending order.

Any help would be much appreciated,
Aakar.






Edit Abuse

推荐答案




在这里,您可以首先根据条件前3个帐户,其中各业务行金额显示在列中,并按降序总和排序"来过滤数据.然后,您可以使用"PIVOT"来格式化输入,如上所述.对于"PIVOT",请参考google的一些很好的链接.

这是"PIVOT"的一些链接.

1.
在SQL查询中使用枢轴的简单方法

2. 使用PIVOT和UNPIVOT

3. SQL SERVER – PIVOT和UNPIVOT表示例

谢谢
西西尔·帕特罗(Sisir Patro)
Hi,

Here you can first filter the data based on the condition "the Top 3 accounts with the individual business line amounts shown in the columns ordered by the sum of the amounts in descending order". Then you can use the "PIVOT" to format your input as mentioned above. For "PIVOT" refer some good links from google.

Here are some links for "PIVOT".

1. Simple Way To Use Pivot In SQL Query

2. Using PIVOT and UNPIVOT

3. SQL SERVER – PIVOT and UNPIVOT Table Examples

Thanks
Sisir Patro


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

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