Counting rows per record:如何统计record为concurent的发票总数量
统计record为concurrent的发票总数量实现方案
注:如果你存储的record字段值为你拼写的
concurent(缺少字母r),直接替换下文方案中的筛选值即可。
SQL 实现
假设数据存储在关系型数据库中,表名为invoice_records,record类型字段为record_type,发票唯一ID字段为invoice_id:
-- 统计去重后的发票总数量 SELECT COUNT(DISTINCT invoice_id) AS concurrent_invoice_total FROM invoice_records WHERE record_type = 'concurrent'; -- 如果表中每行对应一张独立发票,可直接统计行数,性能更高 SELECT COUNT(*) AS concurrent_invoice_total FROM invoice_records WHERE record_type = 'concurrent';
Excel/在线表格实现
- 普通表格场景:假设record类型值存放在A列,直接用COUNTIF函数:
=COUNTIF(A:A,"concurrent") - 结构化表格场景:直接引用表和列名,适配性更强:
=COUNTIF(你的表名[record列名],"concurrent")
Python Pandas 实现
假设数据集已经加载为DataFrame对象df:
# 统计符合条件的行数 concurrent_total = df[df['record_type'] == 'concurrent'].shape[0] # 统计去重后的发票数量,假设发票ID列名为invoice_id concurrent_unique_total = df[df['record_type'] == 'concurrent']['invoice_id'].nunique()
内容的提问来源于stack exchange,提问作者Mystical Me
相关产品推荐
相关产品推荐

