Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    16

    Unanswered: Problems with SQL query / Division

    Hello,

    maybe someone can look over that real quick:

    These are the required tables:

    Code:
    WITH
       Medium
     ( format , name , year ) AS (
    VALUES
     ( 1 , CD   , 1982 )
     ( 2 , DVD  , 1995 )
     ( 7 , Vinyl, 1895 )
    ...
    
    , Release
     ( tracklist , label , country , format , name , year )
    VALUES
     ( 938383 , 2632 , 107 , 1 , 'The Ballad Hits' , 2002 )
     ( 938383 , 8476 , 107 , 1 , 'The Ballad Hits' , 2002 )
     ( 78139  ,  172 , 222 , 1 , 'Live'            , 2003 )
    ....
    This is my code:

    Code:
    SELECT label 
    FROM release r JOIN medium m ON r.format = m.format
    GROUP BY label HAVING COUNT(COUNT r.format) = 
             (SELECT COUNT(DISTINCT m.format) FROM medium);
    In my homework, they want to know the labels, that released albums on ALL formats(CD, Vinyl, Bluray...)

    Does my SQL query look right to you? My problem with, the code, is, it doesn't give me any results.... So I am not 100 % certain, if this is right or not...

    Thanks in advance!

    Tobias

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Please try by removing "m." and replacing COUNT by DISTINCT.
    Code:
    ...
    GROUP BY label HAVING COUNT(COUNT r.format) = 
             (SELECT COUNT(DISTINCT m.format) FROM medium);
    Last edited by tonkuma; 07-01-12 at 10:50. Reason: Add " and replacing COUNT by DISTINCT"

  3. #3
    Join Date
    Jun 2012
    Posts
    16
    Thanks case closed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •