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

我想到的第一件事:

    选择
    电影大师ID,
    MAX(ReleaseDate) 作为 ReleaseDate,
    显示顺序,
    mc_code,
    标题,
    生物铸造,
    生物导演,
    链接词,
    发布标签,
    概要,
    语言,
    分销商订单,
    经销商
    从(
    选择不同的
        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(day,MOVIE_VERSION.ReleaseDate,getdate()) =0))
                然后“刚刚发布”
            别的 ''
        以 RELEASETAG 结束,
        movie_master.简介,
        movie_language.NAME 作为语言,
        案子
            当 movie_master.DistributorID = 8 THEN 0
            否则 9999
        结束为经销商订单,
        movie_distributor.name 作为经销商
    来自电影大师
    左加入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
按 displayorder、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 回答