Oracle with query by with result set [英] Oracle query with group by with result set

查看:64
本文介绍了Oracle with query by with result set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,表格会是这样的



-------------------- -

姓名|金额|

---------------------

Raju | 2000 |

----------------------

Rajesh | 4000 |

----------------------

Raju | 4000 |

--------------------

Rajesh | 10000 |

----------------------



但我需要一个结果集的值将是这样的



------------------

Raju | Rajesh |

-----------------

6000 | 14000 |

-----------------







任何人都可以给我这个查询的想法吗?



我尝试了什么:



当我尝试分组时会产生这样的结果



------------ -------

| Raju | 6000 |

-----------------

Rajesh | 14000 |

-----------------

I have one requirement where the table will be like this

---------------------
Name | Amount |
---------------------
Raju | 2000 |
----------------------
Rajesh | 4000 |
----------------------
Raju | 4000 |
--------------------
Rajesh | 10000 |
----------------------

But i need a values where result set will be like this

------------------
Raju | Rajesh |
-----------------
6000 | 14000 |
-----------------



can anyone give me idea for this query?

What I have tried:

when i tried group by it will result like this

-------------------
|Raju | 6000 |
-----------------
Rajesh | 14000 |
-----------------

推荐答案

选择

sum(当name ='Raju'然后施放(作为varchar(50))结束时的情况)作为Raju,

sum(当name ='Rajesh'然后施放时的情况(数量为varchar) (50))结束)作为Rajesh
来自table_name的
;
select
sum(case when name='Raju' then cast(amount as varchar(50)) end)as Raju,
sum(case when name='Rajesh' then cast(amount as varchar(50)) end)as Rajesh
from table_name;


这篇关于Oracle with query by with result set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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