Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k 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 (55.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
asked Jul 24, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer

Browse Categories

...