本文介绍了如何从多行中选择一个特定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个主表和明细表.对应于master中的ID,我在明细表中将有2/更多行.基于详细信息的ID,我在另一个表(例如table3)中有值.这意味着,如果我有2行详细信息,我将在table3中有2行.表3中有一个字段licensecount,该行的两行值都相同.我需要基于mastertable中的ID查找该licensecount的计数.


问题是当我加入这些表并接受SUM(table3.licensecount)时,我会添加作为结果添加的重复值.例如:如果licensecount是20,我得到的是40,我应该得到的是20..


谁能帮助我.在此先感谢

Hi guys,

I have a master table and detail table.Corresponding to an ID in master i will have 2/more rows in detail table. Based on the ID of detail i have values in another table say table3. That means if i have 2 rows in detail i will have 2 rows in table3. There is a field licensecount in table 3 and both rows wil have same values for that column. I need to find count of that licensecount based on the id in the mastertable.


The problem is when i join these table and take SUM(table3.licensecount) i ger the duplicate values added as result. For ex: if the licensecount is 20 what i get is 40 where i should be getting is 20..


Can anyone pls help me out. Thanks in advance

推荐答案

select count(licensecount) from
table1,table2,table3
where
table2.sameid= table3.sameid
and table2.id = table1.id



谢谢
Milind



Thanks
Milind



这篇关于如何从多行中选择一个特定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:06