我正在使用 SQL Server 2008,并且有两个单独的 Count 查询。我想将这两个查询相除并乘以 100 得到一个百分比。
两个查询
SELECT COUNT(*) FROM
(
SELECT * FROM admin WHERE principal LIKE '%Mrs%'
UNION
SELECT * FROM admin where deputy_principal LIKE '%Mrs%'
) as Count1
SELECT COUNT(*) * 2 FROM admin as Count2
我尝试过这样的事情:
SELECT(
SELECT COUNT(*) FROM
(
SELECT * FROM admin WHERE principal LIKE '%Mrs%'
UNION
SELECT * FROM admin where deputy_principal LIKE '%Mrs%'
)
/
(
SELECT COUNT(*) * 2 FROM admin as Count2
)
)
但是我得到了无法正确调试的语法错误。哪种方法是正确的?
它应该将 Count1 和 Count2 相除,然后乘以 100 并显示如下:
37%