0

私は次のものを持っています:

SELECT nominees.personname, awards.name as awards, nominees.filmname 
FROM nominees, awards WHERE nominees.aid = awards.aid and nominees.personname is not 
NULL GROUP BY nominees.personname, awards.name, nominees.filmname 
ORDER BY nominees.personname;

これにより、次の表が生成されます。

"personname"    "awards"        "filmname"

"Ang Lee"       "director"      "Life of Pi"
"Anglelina J."  "actress"       "The Tourist"
"Ann Dowd"   "supporting actress"   "Compliance"
"Anne Hathaway" "actress"      "Love and Other Drugs"
"Anne Hathaway" "supporting actress"  "Les Misrables"
"Annette Bening"    "actress"   "The Kids Are All Right"
"Another Year"  "screenplay"    "Mike Leigh"
"A.R. Rahman"     "score"       "127 Hours"
"AR Rahman"       "score"       "127 Hours"
"Barbara Hershey"   "supporting actress"    "Black Swan"
"Ben Affleck"   "actor"         "Argo"
"Ben Affleck"   "director"      "Argo"

同じ映画で 2 つの別々の賞にノミネートされた人物のみを含むセットを入手しようとしています。この特定のテーブルでは、'Ben Affleck' だけです。

結果は

    "personname"    "awards"        "filmname"

    "Ben Affleck"   "actor"         "Argo"
    "Ben Affleck"   "director"      "Argo"

しかし、私はそれを得ることができないようです.HAVINGと何らかのカウントメソッドを使用しようとしましたが、それを機能させることができませんでした. どんな助けでも大歓迎です。

4

2 に答える 2

0

私はそれが次のように動作するはずだと思います:

SELECT nominees.personname, awards.name as awards, nominees.filmname, count(distinct  awards.name) as number_awards
FROM nominees, awards WHERE nominees.aid = awards.aid and nominees.personname is not 
NULL 
GROUP BY nominees.personname, awards.name, nominees.filmname 
HAVING number_awards > 1
ORDER BY nominees.personname;
于 2013-03-05T20:42:48.353 に答える