0 votes
1 view
in SQL by (22.4k points)

Division in sqlite return integer value

sqlite> select totalUsers/totalBids from 

(select (select count(*) from Bids) as totalBids , 

(select count(*) from Users) as totalUsers) A;

1

Can we typecast the result to get the real value of division result?

1 Answer

0 votes
by (34.6k points)

If we divide an integer by another integer then the result value will be round off to the nearest integer. So, you can either multiply one of the fields by 1.0 or use CAST to convert one of the fields to float as follows:

select (totalUsers*1.0)/totalBids from

(select (select count(*) from Bids) as totalBids ,

(select count(*) from Users) as totalUsers) A;

1

or

select CAST (totalUsers as FLOAT) / totalBids from

(select (select count(*) from Bids) as totalBids ,

(select count(*) from Users) as totalUsers) A;

1

You can go through this SQL Tutorial by Intellipaat to learn more about type conversions.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 24, 2019 in SQL by Tech4ever (22.4k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...