Skip to main content
Solved

ROUNDING PERCENTAGE SQL


Forum|alt.badge.img+7

Does any one know how i can adjust the below SQL so that it rounds to the nearest whole number. i am trying to see 10% of records to count a month. Below is current SQL 

 

I have tried adding Round in the front but it wouldnt work

 

(CASE WHEN LAST_COUNT_DATE >trunc(to_date( '#START_OF_THIS_YEAR#', 'YYYY-MM-DD-HH24:MI:SS' )) THEN '0' ELSE '1' END) *.10

 

 

Best answer by paul harland

seems like you need a group by clause.

In the absence of that, each row is just going to return either 0 or 1; multiplied by 0.1 = 0.1.

You need group by contract and then sum & Round.

round(sum(CASE WHEN LAST_COUNT_DATE >trunc(to_date( '#START_OF_THIS_YEAR#', 'YYYY-MM-DD-HH24:MI:SS' )) THEN '0' ELSE '1' END) *.10 , 0)

View original
This topic has been closed for comments

paul harland
Superhero (Employee)
Forum|alt.badge.img+24

seems like you need a group by clause.

In the absence of that, each row is just going to return either 0 or 1; multiplied by 0.1 = 0.1.

You need group by contract and then sum & Round.

round(sum(CASE WHEN LAST_COUNT_DATE >trunc(to_date( '#START_OF_THIS_YEAR#', 'YYYY-MM-DD-HH24:MI:SS' )) THEN '0' ELSE '1' END) *.10 , 0)


Forum|alt.badge.img+7
  • Sidekick
  • January 8, 2021

Thank you not sure why that didn’t cross my mind you helped me one earlier using the same set up, thank you again


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings