具有多列的不同计数 [英] Distinct count with multiple columns
问题描述
Hello All,
Hello All,
如何使用select和group by语句中的多列获取非重复计数。没有列我得到不同的计数,多列获得巨大的数量。每当计算数据的不同成员时,如果同一成员在同月或未来月份重复
,我只需要考虑一次。您能否请帮助我们如何避免重复计数与列数。
how to get the distinct count with multiple columns in select and group by statements. Without columns i am getting the different count, with multiple columns getting huge number count. whenever count the distinct member for data, if the same member is repeating in same month or future months i need to be considered as only one time. can you please help to how to avoid the duplicate counts with number of columns.
年月ID
year month id
2017 01    345
2017 01 345
2017 02   345
2017 02 345
2017 02    346
2017 02 346
2017 03   345
2017 03 345
2017 03   346
2017 03 346
2017 03   347
2017 03 347
---最终结果:
年月ID
year month id
2017 01    345
2017 01 345
2017 02    346
2017 02 346
2017 03   347
2017 03 347
谢谢,
CMK
推荐答案
你好,
研究'使用X AS'并通过2-3个简单步骤构建您需要的步骤,每个步骤都可以理解。
Study 'WITH X AS' and build what you need to get with 2-3 simple steps, each of which you can understand.
并且..我无法理解为什么在源数据上
And... I can't understand why on source data
2017 03   345
2017 03   346
2017 03   347
2017 03 345
2017 03 346
2017 03 347
摸索的结果假设是
the result of groping suppose to be
2017 03   347
您是否选择MAX(ID)作为第三列的结果?
Do you select MAX(ID) as result for third column?
这篇关于具有多列的不同计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!