0

I'm using below query to generate the percentage in a new column but I want only two decimal places.

    SELECT 
count( *) TestCount
,count(case when result_status = 'Not A Finding' then 1 end) TestPassedCount
,count(case when result_status = 'Not A Finding' then 1 end) / count(*) ThePercentage
,asset 
 FROM Table_Name
 group by asset

Current Output:

             TestCount  TestPassedCount    Percentage   Asset
                 18             7          0.388888889  DB2MOTIV:DBMOTIVA@mxemch010405ads.mx.hsbc

Required Output:

             TestCount  TestPassedCount    Percentage   Asset
                 18             7              38.89    DB2MOTIV:DBMOTIVA@mxemch010405ads.mx.hsbc

Regards,

Bharath Vikas

Vikas
  • 199
  • 1
  • 7

3 Answers3

0

Assuming that is what you want to achieve, just multiply your result with 100 and add round function:

SELECT 
 count( *) TestCount
 ,count(case when result_status = 'Not A Finding' then 1 end) TestPassedCount
 ,round((count(case when result_status = 'Not A Finding' then 1 end) / count(*)) * 100,2) ThePercentage
 ,asset 
FROM 
 Table_Name
group by 
 asset
dns_nx
  • 3,651
  • 4
  • 37
  • 66
0

Use ROUND method

 SELECT 
        count( *) TestCount
        ,count(case when result_status = 'Not A Finding' then 1 end) TestPassedCount
        ,ROUND((count(case when result_status = 'Not A Finding' then 1 end) / count(*))*100,2) ThePercentage
        ,asset 
         FROM Table_Name
         group by asset
Edward N
  • 997
  • 6
  • 11
0

Try this:

 Round(  count(case when result_status = 'Not A Finding' then 1 end) / count(*) * 100 , 2) ThePercentage
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69