如何避免重复的值 [英] How to avoid the duplicate values

查看:69
本文介绍了如何避免重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想取一个table1的总和并显示在表2中:

我正在使用两个名为Table1&的表.表2

我正在使用左外部联接来连接该表中的两个表,我想从一个表中获取我要返回的存储过程的金额总和,就像这样

Hi,

I want to take the sum of a table1 and display it in table two:

I am using two tables named Table1 & Table2

I am using left outer join for joining both the tables in that table I want to take the Sum of the Amount from a table the stored procedure I have return like this

select Distinct 'BL' as BillID, '' Currency, SUM(P.BOQPriceINR)as PriceINR
,SUM(P.BOQCOSTINR) as COSTINR ,S.ProjectMilestoneId from Table1 S with(nolock)
left outer join  Table2 P with(nolock)  on P.Code=S.Code and P.Id=s.Id and p.tRevNo=S.RevNo
where S.Code=001 and S.Id=1113120007 and S.RevNo=0 group by S.ProjectMilestoneId



如果我执行此存储过程,则由于行table2包含一个名为currencycode的字段,因此正在复制该行,则货币代码将以INR或USD表示.我想在单行中显示总和.如何执行此操作请帮助我解决此问题.

EG:



If I execute this stored procedure It is duplicating the row because the table2 contains the field called currncycode the currency code will be in INR or USD If I take sum both the currency it is duplicating. I want to display the sum in single line. How to do this one Please help me to solve this issue.

EG:

BillID   Currency   PriceINR    COSTINR   ProjectMilestoneId

BL1                  5000         4000          1        from Table1
BL1                  2000         3000          1        from Table1
BL1.1     INR        5000         4000                   from table2
BL1.1     USD        2000         3000                   from Table2





我想要这样的答案





I want the answer like this

BillID   Currency   PriceINR    COSTINR   ProjectMilestoneId

BL1                  7000         7000          1        from Table1
BL1.1     INR        5000         4000                   from table2
BL1.1     USD        2000         3000                   from Table2





在Advance中致谢





Thanks in Advance

推荐答案

也将BillID放在group by子句中.
Put BillID also in group by clause.


这篇关于如何避免重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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