2011-11-14 7 views

答えて

3

どの程度

よう MAX(count)

何かを持っているだけで、それらの俳優を、返されますので、どのように私は私の最初のSQLを変更することができます

Tom Waits | 10 
Tom Waits | 30 

があることができ

SELECT actors.id 
     , MAX(actors.count) 
FROM artists 
     INNER JOIN actors ON artists.title = actors.title 
GROUP BY 
     actors.id   
+0

それはそれです:)ありがとう – fl00r

+0

あなたを歓迎します。 –

-1
SELECT 
    artists.id, 
    actors.id, 
    MAX(actors.count) 
FROM 
    artists 
INNER JOIN actors ON artists.title = actors.title; 
GROUP BY 
    actors.id 
+0

いくつかのGROUP BY条件がここにありません。 – Benoit

1

彼の1 -

SELECT artists.id, actors.id, actors.`count` FROM artists 
    INNER JOIN actors 
    ON artists.title = actors.title 
    INNER JOIN (
    SELECT title, MAX(`count`) max_count FROM actors 
     GROUP BY title 
    ) actors2 
    ON actors.title = actors2.title AND actors.`count` = actors2.max_count; 
1
SELECT artists.id, a.id, a.count 
FROM artists 
INNER JOIN (SELECT actors.id, actors.count 
      FROM actors 
      HAVING MAX(actors.count)) a ON artists.title = a.title 
+0

興味深いアプローチ、ありがとう! – fl00r

0

簡単な方法:トムのための投票アップ

SELECT 
    artists.id, 
    (select actors.id 
    from actors 
    where artists.title = actors.title 
    order by actors.count desc Limit 1) 
    as actors_id, 
    (select actors.count 
    from actors 
    where artists.title = actors.title 
    order by actors.count desc Limit 1) 
    as actors.count 
FROM 
    artists 
; 
関連する問題