Using OVER() if customer has watch gladiator then 1 else 0 SQL SERVER

前端 未结 4 480
攒了一身酷
攒了一身酷 2021-01-27 08:27

I think I need some guidance as to what is wrong in my query. I am trying to do

Watched_Gladiator=CASE WHEN FilmName IN (CASE WHEN FilmName LIKE \'%Gladiator%\'         


        
4条回答
  •  执笔经年
    2021-01-27 09:02

    Try grouping up to the cust/film level:

    select
    cust_nbr,
    case when film_name like '%Gladiator%' then 1 else 0 end
    from
    (
    select
        cust_nbr,
        film_name
        from
        
        group by
        cust_nbr,
        film_name
    ) t
    

    Or, as an alternative:

    select distinct cust_nbr
    from
    
    where 
    filmname = 'Gladiator'
    

提交回复
热议问题