如何从多行中选择一个特定的值 [英] how to select a particular value from multiple rows

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

问题描述

大家好,

我有一个主表和明细表.对应于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

推荐答案

提供的数据很少,问题也很少.

但是请尝试如下所示,通过更换适当的外键进行操作.

There is very less data provided and question is little vague.

But try as shown below by replaceing proper foreign keys.

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



谢谢
Milind



Thanks
Milind


您尚未提供一些表格数据& sql-Query.

尝试与众不同

检查加入类型& 条件申请加入.

祝您编码愉快!
:)
you have not provide some table data & sql-Query.

try distinct
or
check type of join & conditions applied for join.

Happy Coding!
:)


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

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