Skip to content
Advertisement

count of distinct columns using group by and calculating percentage

Trying to write a sql query:

below is normal output

I need row wise percentage output for tidcounts:

The query I’m trying is below

expected output is:

Please suggest if i am missing anything it should be in either spark-sql or pyspark

Advertisement

Answer

Solution with spark.sql

Solution with pyspark


Example

Result

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement