SELECT COUNT (distinct CLIEND_ID) Fromclients_data 表有什么奇怪的行为?
您能解释一下 count (distinct client_id) 语句的这种奇怪行为吗?
for :
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0
我有 6000 行
,因为
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0 and cif_type = 'CARD'
我有 5964 行 因为
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0 and cif_type = 'LOAN'
我有 42 行。 但是
5964 + 42 = 6006
第一个查询只得到 6000 。 这额外的 6 行从哪里来?
注意:目前无法提供任何建议的数据。 图片位于此处:
Could you please Explain this strange behavior of count (distinct client_id) statement.
for :
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0
I have got 6000 rows
and for
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0 and cif_type = 'CARD'
I have got 5964
and for
SELECT count(distinct client_id)
from clients_data where bank_name ='SABB' and tstatus = 0 and cif_type = 'LOAN'
I have got 42 rows .
but
5964 + 42 = 6006
and the first query gets only 6000 .
where these extra 6 rows come from ?
Note : Data now is not Available for any suggestions .
the image is here :
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可能有六个同时拥有 CARD 和 LOAN 的
client_id
。There could be six
client_id
that have both a CARD and a LOAN.您是否有特定 client_id 的多个记录?运行上面的命令会告诉你。
Do you have multiple records for a specific client_id? Running the above will tell you.
建议 6 个 client_ids 出现在 cif_type 为“LOAN”的行以及 cif_type 为“CARD”的行中。尝试在不使用 DISTINCT 的情况下计算 3 个条件中的行数。您应该找到数字然后将其相加。
Suggest 6 of your client_ids appear in rows with a cif_type of 'LOAN' and also in rows with a cif_type of 'CARD'. Try counting rows in your 3 conditions without the DISTINCT. You should find the numbers then add up.
可能您有一些值为空或 null cif_type 的值。
May be u have some values which have empty or null cif_type .