1
SELECT id,icon,type,cnt 
FROM  capability 
JOIN (
    SELECT s0_.capability_id AS capability_id0 ,
           count(capability_id) as cnt  
    FROM service_offer_capability s0_ 
    INNER JOIN service_offer s1_ ON s0_.service_offer_id = s1_.id 
    WHERE s0_.value <> 'i:0;' AND s1_.service_id = 2 
    GROUP BY s0_.capability_id
) af
ON af.capability_id0=id;

私がやりたいのは、余分な列として max(cnt) を持つことだけです。cnt で注文して最初のものを入手できることは知っていますが、別の方法を探しています.それは可能ですか、それとも複数のクエリを実行する必要がありますか?

4

1 に答える 1

3

これはそれを行う必要があります:

SELECT id,
       icon,
       type,
       cnt,
       max(cnt) over () as max_cnt
FROM  capability 
JOIN (
    SELECT s0_.capability_id AS capability_id0 ,
           count(capability_id) as cnt  
    FROM service_offer_capability s0_ 
    INNER JOIN service_offer s1_ ON s0_.service_offer_id = s1_.id 
    WHERE s0_.value <> 'i:0;' AND s1_.service_id = 2 
    GROUP BY s0_.capability_id
) af
ON af.capability_id0=id;
于 2012-04-18T14:15:27.353 に答える