create table #t (maker varchar(100), model varchar(100...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

create table #t (maker varchar(100),   model  varchar(100), type varchar(100) );
insert into #t ( maker,   model,   type )  values 
( 'B',   '1121',    'pc'),
( 'A',   '1233',    'pc'),
( 'E',   '1260',    'pc');

;with 
totals as (
   select maker, type,
       count( * ) as n
   from
       #t
   group by 
      maker,  type
      ) ,
maker_type as (
   select distinct maker, type
   from #t
)
select 
   mm.*, t.n, 
   case  when t.n is null then 'No' else 'Yes' end as yes_no
from
   maker_type mm
left outer join
   totals t
      on mm.maker = t.maker and
         mm.type = t.type

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached