0

我正在尝试通过第二个查询第一个查询,我该怎么做?

SELECT COUNT(*) AS Result
FROM pparsdb.application
    INNER JOIN pparsdb.planning_scheme
    ON application.planning_scheme = planning_scheme.ps_code
    WHERE planning_scheme.markus_ra = 'GA'

SELECT Result / COUNT(*)
FROM pparsdb.planning_scheme 
WHERE markus_ra = 'GA'
4

2 回答 2

2

试试这个,

SELECT  COUNT(*) / crss.totalCount AS Result
FROM    pparsdb.application
        INNER JOIN pparsdb.planning_scheme
            ON application.planning_scheme = planning_scheme.ps_code
        CROSS JOIN
        (
            SELECT  COUNT(*) totalCount
            FROM    pparsdb.planning_scheme 
            WHERE   markus_ra = 'GA'
        ) crss
WHERE   planning_scheme.markus_ra = 'GA'
于 2013-05-23T00:21:50.353 回答
2

假设每个应用程序只有一个计划方案,下面是一种只使用一个查询而没有子查询的方法:

SELECT COUNT(a.planning_scheme) / COUNT(*) AS Result
FROM pparsdb.planning_scheme ps left outer join
     pparsdb.application a
     ON a.planning_scheme = ps.ps_code
WHERE ps.markus_ra = 'GA'

即使该条件不成立,您也可以执行以下操作:

SELECT COUNT(a.planning_scheme) / COUNT(distinct ps.planning_scheme) AS Result
FROM pparsdb.planning_scheme ps left outer join
     pparsdb.application a
     ON a.planning_scheme = ps.ps_code
WHERE ps.markus_ra = 'GA'
于 2013-05-23T00:39:44.043 回答