11 June, 2013

Percentage Calculation using Oracle 10g

Write the following simple query:

Select Column1,Column2,Column3,TRUNC(((ratio_to_report(count(*)) over(partition by PartitionColumn1,PartitionColumn2))*100),4) as Percent
                from Table_Name
                where <condition>
                group by Column1,Column2,Column3

N.B.:
  • Column1, Column2,Column3 are just column name of your table.
  • PartitionColumn1,PartitionColumn2 are column name of your table, by using these column name you calculate the percentage or partition table. It's may be one or more column.
  • 100 means calculate percentage in 100.

No comments:

Post a Comment