I tried to divide two columns from joined tables but the result (value of column relative_duration) is always 0. The query is the following:
SELECT t1.[user_1]
,t1.[user_2]
,t1.[total_duration]
,(t1.total_duration/t2.[total_events_duration]) AS relative_duration
FROM [CDRs].[dbo].[aggregate_monthly_events] AS t1 INNER JOIN [CDRs].[dbo].[user_events_monthly_stats] AS t2 ON t1.[user_1] = t2.[user_1]
Does anyone know what could be wrong in the query above and how to fix it in order to divide column total_duration from table t1 with column total_events_duration from table t2?
BTW I tried to replace division with subtraction ("/" with "-") and in that case the column relative_duration is not 0.
To divide columns in Excel, just do the following: Divide two cells in the topmost row, for example: =A2/B2. Insert the formula in the first cell (say C2) and double-click the small green square in the lower-right corner of the cell to copy the formula down the column. Done!
Type the equal sign, and use cell references instead of typing regular numbers. For instance, if you want to divide cell A1 by cell B1, type =A1/B1. If you want to divide a cell by a constant number such as 5, you would type =A1/5. When you press enter, Excel displays the result in the cell.
Example 1:The simple division (/) operator is the first way to divide two columns. You will split the First Column with the other columns here. This is the simplest method of dividing two columns in Pandas. We will import Pandas and take at least two columns while declaring the variables.
Presumably, those columns are integer columns - which will be the reason as the result of the calculation will be of the same type.
e.g. if you do this:
SELECT 1 / 2
you will get 0, which is obviously not the real answer. So, convert the values to e.g. decimal and do the calculation based on that datatype instead.
e.g.
SELECT CAST(1 AS DECIMAL) / 2
gives 0.500000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With