Trying to write a sql query:
select indicator, count(distinct tid) as tidcount
from coa
group by indicator
below is normal output
indicator tidcount
M 6219
Z 411424
S 1
I 1
I need row wise percentage output for tidcounts:
The query I'm trying is below
spark.sql(""" select indicator ,count(tid) as tidcount , round(round(count(indicator)/sum(count(indicator)) over (), 4)* 100, 4) as PERCENTAGE_TOTALS from coa group by indicator """)
indicator tidcount Percentage_total
M 6219 0.72
Z 411424 98.78
S 1 .49
I 1 .02
expected output is:
indicator tidcount Percentage_total
M 6219 1.4
Z 411424 98.5
S 1 .0002
I 1 .0002
Please suggest if i am missing anything it should be in either spark-sql or pyspark