简体   繁体   中英

Computing division between the number of rows of two tables in sql server

I have two tables A and B. Number of rows of A is x, number of rows of B is y, and I need to compute x/y. How to do all this in one sql request.
Here is what I have tried so far :

select round(final,1) as final 
from (select count(*) from A/select count(*) from B )  

But this is not working because of syntax issue I think.
Any help greatly appreciated .

You just have to use two sub queries:

SELECT Round( (SELECT Count(*) FROM   a) 
            / (SELECT Count(*) FROM   b), 1) AS final 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM