Sql 列出B列中的所有值,并计算A列中至少有一条记录对应A和B的不同值
列出B列中的所有值,并计算A列中至少有一条记录对应A和B的不同值Sql 列出B列中的所有值,并计算A列中至少有一条记录对应A和B的不同值,sql,Sql,列出B列中的所有值,并计算A列中至少有一条记录对应A和B的不同值 File name | File extension -------------------------- 100011 | txt 100011 | pdf 100017 | txt 100017 | pdf 100017 | txt 100018 | pdf 100018 | xls 预期结果 txt | 2 pdf | 3 xls | 1 使用
File name | File extension
--------------------------
100011 | txt
100011 | pdf
100017 | txt
100017 | pdf
100017 | txt
100018 | pdf
100018 | xls
预期结果
txt | 2
pdf | 3
xls | 1
使用不同的计数
select fileextension,count( distinct filename) from table
group by fileextension
您需要使用distinct:countdistinct文件名