需要在SQL中编写查询以获取所需的输出 [英] Need to write a query in SQL to for desire output

查看:70
本文介绍了需要在SQL中编写查询以获取所需的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Hi,

My sql table is below

A	B	C	D	E	Amount
322	H7731	8	31981	31962	1
322	H7731	8	31981	31962	2
322	H7731	8	31981	31962	3
322	H7732	9	31961	389	11
322	H7733	8	31962	379	22
322	H7734	11	31982	31963	5
322	H7734	11	31982	31963	2
322	H7734	11	31982	31963	3
338	H7735	12	369	222	21
338	H7735	12	369	222	22


I want a query which return below table on the behalf of column A , B , C, D, E if duplicates rows found then make a sum of value present in column Amount  and update in any single row of these record and delete remaining duplicate rows.

A	B	C	D	E	Amount
322	H7731	8	31981	31962	6
322	H7732	9	31961	389	11
322	H7733	8	31962	379	22
322	H7734	11	31982	31963	10
338	H7735	12	369	222	43





提前致谢



我尝试过:



group by和having子句但它最多只有2行duplicity



Thanks in advance

What I have tried:

group by and having clause but it is only for maximum 2 rows duplicity

推荐答案

试试这个:

Try this:
SELECT A,B,C,D,E,SUM(Amount) FROM tablename GROUP BY A,B,C,D,E


这篇关于需要在SQL中编写查询以获取所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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