Division operator (/) returning 0 in a custom SQL query

I am trying to import a dataset using a custom SQL query. I would like to divide field B (all patients) by field A (patients with the specified comorbidity). However, every time the result seems to be 0.0, even if it should be closer to 1.0. The problem seems to persist every time the result is less than 1. Would anyone be able to help?

Hi @ekricha - Welcome to AWS community and thanks for posting the question. Can you please share the custom sql ( do not share PCI and PII info) and also what the input data types for field A and B, possibly you can use CAST to decimal precision. Please share the screenshot and sample input data and expected output so that we can help you in resolving the issue.

Regards - Sanjeeb

Thank you for your reply, @Sanjeeb2022. I have added a screenshot of my SQL query

Thanks @ekricha , what is your source data base type ( is it MY SQL ?) please confirm.

Regards - Sanjeeb

The data is from Redshift

Thanks @ekricha - Can you try to cast the fields to decimal (10,2) in your CTE tables and then do the division.

If it is not working, i will spend sometime to create a Redshift cluster and try it from my side.

Please check and share your outcomes.

Regards - Sanjeeb

1 Like

Thenk you @Sanjeeb2022 - I casted the original calculated fields to decimals and this worked.

Hi @ekricha - Thank you and glad that issue is resolved. Have a wonderful day.

Regards - Sanjeeb

1 Like