count(col1, col2) 可以统计 多个字段的非空记录
+---+-----+-----+ | id| name|score| +---+-----+-----+ | 1|alice| 90| | 2| null| 85| | 3|alice| 95| | 4| Bob| 100| | 5|alice| 95| +---+-----+-----+ >>> spark.sql(""" select count(distinct name,score) from table1 """).show() +---------------------------+ |count(DISTINCT name, score)| +---------------------------+ | 3| +---------------------------+ >>> spark.sql(""" select count(name,score) from table1 """).show() +------------------+ |count(name, score)| +------------------+ | 3| +------------------+ >>> spark.sql(""" select count(*) from( select distinct name, score from table1 ) a """).show() +--------+ |count(1)| +--------+ | 4| +--------+