0

以下はクエリです

select DISTINCT movie_master.MovieMasterID, MOVIE_VERSION.ReleaseDate, 
movie_master.displayorder,movie_classification.mc_code,
movie_master.title As Title,
movie_master.BioCast,movie_master.BioDirector,movie_master.LinkWord,
CASE WHEN ((DATEDIFF(day,MOVIE_VERSION.ReleaseDate,getdate())  <=7) and (DATEDIFF(day,MOVIE_VERSION.ReleaseDate,getdate()) >=0)) THEN 'JUST RELEASED' ELSE '' END AS RELEASETAG,
movie_master.Synopsis,movie_language.NAME as Language,
CASE WHEN movie_master.DistributorID = 8 THEN 0 ELSE 9999 END AS distributororder,
movie_distributor.name as distributor
from movie_master 
left join MOVIE_LANGUAGE on MOVIE_MASTER.Language = movie_language.languageid
left join movie_distributor on MOVIE_MASTER.distributorid = movie_distributor.distributorid
left join movie_version on MOVIE_MASTER.MovieMasterID = MOVIE_VERSION.MovieMasterID
left join movie_classification on MOVIE_MASTER.classification = movie_classification.classificationid
left join movie_itemdetails on MOVIE_MASTER.MovieMasterID = movie_itemdetails.MovieMasterID 
where MOVIE_VERSION.ReleaseDate <= convert(varchar, GETDATE(), 101) 
and MOVIE_VERSION.MovieMasterID = movie_master.MovieMasterID
and movie_master.classification = movie_classification.classificationid
and movie_master.MovieMasterID = movie_itemdetails.MovieMasterID and movie_itemdetails.fieldid = 1 and movie_itemdetails.Type ='TRAILER'
and ((MOVIE_VERSION.FilmCode in (SELECT DISTINCT FILMID FROM MOVIE_TEMP)) OR (MOVIE_VERSION.Title in (SELECT DISTINCT TITLE FROM MOVIE_TEMP)))  
AND LEFT(MOVIE_VERSION.FILMCODE,1) <> 6
and MOVIE_VERSION.Enabled = 1
AND MOVIE_MASTER.Enabled = 1
AND (MOVIE_MASTER.MovieMasterID in (SELECT DISTINCT MOVIE_MASTER.MovieMasterID FROM MOVIE_MASTER))
order by MOVIE_MASTER.displayorder, MOVIE_VERSION.ReleaseDate desc, distributororder, MOVIE_MASTER.TITLE

および結果セット

310 2013-03-01 00:00:00.000 9999    NA  test456             JUST RELEASED       NA  9999
310 2013-02-28 00:00:00.000 9999    NA  test456             JUST RELEASED       NA  9999
244 2013-02-10 00:00:00.000 9999    U   I Love Hong Kong 2013   Alan Tam, Veronica Yip, Natalis Chan, Eric Tsang, Stanley Fung, Bosco Wong, Michael Tse, Kate Tsui, Joyce Cheng Chung Shu-Kai           The story takes place in the 1970s until modern times, in which all families are happily prepare and welcome the Chinese New Year in Hong Kong. However, a traditional restaurant in Yau Ma Tei faces terrible problem. At last, everything solved with the neighbours’ kind support and assistance as happy ending.    CANTONESE   0

私の質問は、同じレコードを区別するためにクエリをさらに強化するにはどうすればよいですか?

4

3 に答える 3

0

最後の日付を選択し、選択リストの別の項目によるグループ化を追加できます。

select DISTINCT movie_master.MovieMasterID, max(MOVIE_VERSION.ReleaseDate),
movie_master.displayorder, movie_classification.mc_code,
movie_master.title As Title,
movie_master.BioCast, movie_master.BioDirector, movie_master.LinkWord,
CASE WHEN ((DATEDIFF(day,max(MOVIE_VERSION.ReleaseDate),getdate())  <=7)
and (DATEDIFF(day,max(MOVIE_VERSION.ReleaseDate),getdate()) >=0))
THEN 'JUST RELEASED' ELSE '' END AS RELEASETAG,
movie_master.Synopsis,movie_language.NAME as Language,
CASE WHEN movie_master.DistributorID = 8 THEN 0 ELSE 9999 END AS distributororder,
movie_distributor.name as distributor
...
group by movie_master.MovieMasterID, movie_master.displayorder, movie_classification.mc_code,
movie_master.title, movie_master.BioCast, movie_master.BioDirector,
movie_master.LinkWord, movie_master.Synopsis,
movie_language.NAME, movie_master.DistributorID, movie_distributor.name
order by MOVIE_MASTER.displayorder, max(MOVIE_VERSION.ReleaseDate) desc, distributororder, MOVIE_MASTER.TITLE
于 2013-03-05T10:15:03.667 に答える
0

最初に頭に浮かんだこと:

    選択する
    MovieMasterID、
    MAX(ReleaseDate) を ReleaseDate として、
    表示順、
    mc_code、
    題名、
    バイオキャスト、
    バイオディレクター、
    リンクワード、
    リリースタグ、
    あらすじ、
    言語、
    代理店注文、
    卸売業者
    から(
    DISTINCT を選択
        movie_master.MovieMasterID、
        MOVIE_VERSION.ReleaseDate,
        movie_master.displayorder、
        movie_classification.mc_code,
        movie_master.title タイトルとして、
        movie_master.BioCast、
        movie_master.BioDirector、
        movie_master.LinkWord、
        場合
        WHEN ((DATEDIFF(日,MOVIE_VERSION.ReleaseDate,getdate()) =0))
                その後、「リリースされたばかり」
            そうしないと ''
        END AS RELEASETAG、
        movie_master.あらすじ、
        movie_language.NAME を言語として、
        場合
            WHEN movie_master.DistributorID = 8 THEN 0
            その他 9999
        END ASディストリビューター注文、
        ディストリビューターとしての movie_distributor.name
    movie_master から
    MOVIE_LANGUAGEに参加
        MOVIE_MASTER.Language = movie_language.languageid で
    左結合 movie_distributor
        MOVIE_MASTER.distributorid = movie_distributor.distributorid で
    左結合 movie_version
        MOVIE_MASTER.MovieMasterID = MOVIE_VERSION.MovieMasterID で
    左結合 movie_classification
        MOVIE_MASTER.classification = movie_classification.classificationid について
    左結合 movie_itemdetails
        MOVIE_MASTER.MovieMasterID = movie_itemdetails.MovieMasterID で
    ここで MOVIE_VERSION.ReleaseDate 6
        および MOVIE_VERSION.Enabled = 1
        AND MOVIE_MASTER.Enabled = 1
        AND (MOVIE_MASTER.MovieMasterID in (SELECT DISTINCT MOVIE_MASTER.MovieMasterID FROM MOVIE_MASTER))

    ) T
    GROUP BY MovieMasterID,displayorder,mc_code,Title,BioCast,BioDirector,LinkWord,RELEASETAG,Synopsis,Language,distributororder,distributor
表示順順、ReleaseDate desc、distributororder、TITLE
于 2013-03-05T10:29:23.177 に答える
0

このクエリを試してください

select DISTINCT movie_master.MovieMasterID, 
                m.ReleaseDate, 
                movie_master.displayorder,movie_classification.mc_code,
                movie_master.title As Title,
                movie_master.BioCast,movie_master.BioDirector,movie_master.LinkWord,
CASE WHEN ((DATEDIFF(day,m.ReleaseDate,getdate())  <=7) and (DATEDIFF(day,m.ReleaseDate,getdate()) >=0)) THEN 'JUST RELEASED' ELSE '' END AS RELEASETAG,
movie_master.Synopsis,movie_language.NAME as Language,
CASE WHEN movie_master.DistributorID = 8 THEN 0 ELSE 9999 END AS distributororder,
movie_distributor.name as distributor
from movie_master 
left join MOVIE_LANGUAGE on MOVIE_MASTER.Language = movie_language.languageid
left join movie_distributor on MOVIE_MASTER.distributorid = movie_distributor.distributorid
left join movie_version m on MOVIE_MASTER.MovieMasterID = m.MovieMasterID
left join movie_classification on MOVIE_MASTER.classification = movie_classification.classificationid
left join movie_itemdetails on MOVIE_MASTER.MovieMasterID = movie_itemdetails.MovieMasterID 
where m.ReleaseDate <= convert(varchar, GETDATE(), 101) 
and m.MovieMasterID = movie_master.MovieMasterID
and movie_master.classification = movie_classification.classificationid
and movie_master.MovieMasterID = movie_itemdetails.MovieMasterID and movie_itemdetails.fieldid = 1 and movie_itemdetails.Type ='TRAILER'
and ((m.FilmCode in (SELECT DISTINCT FILMID FROM MOVIE_TEMP)) OR (m.Title in (SELECT DISTINCT TITLE FROM MOVIE_TEMP)))  
AND LEFT(m.FILMCODE,1) <> 6
and m.Enabled = 1
AND MOVIE_MASTER.Enabled = 1
AND (MOVIE_MASTER.MovieMasterID in (SELECT DISTINCT MOVIE_MASTER.MovieMasterID FROM MOVIE_MASTER))
AND EXISTS (
            SELECT 1
            FROM movie_version m2
            WHERE MOVIE_MASTER.MovieMasterID = m2.MovieMasterID
            HAVING MAX(m2.ReleaseDate) = m.ReleaseDate
            )            
order by MOVIE_MASTER.displayorder, m.ReleaseDate desc, distributororder, MOVIE_MASTER.TITLE
于 2013-03-05T10:43:03.980 に答える