如题:(请教查询同姓)一个名单表,怎样查询出同姓的人数(为了显示更加清晰,查出同一个姓的人数在2人以上的人数或者名字)列出他们的姓名或者同一个姓的人数谢谢!~

解决方案 »

  1.   

    select left(姓名,1),count(*) from tb group by left(姓名,1) having count(*)>=2
      

  2.   

    left(name,1)相等--单姓,李、
    union
    left(name,2)相等--双姓,欧阳、
      

  3.   

    select * form t1 where name like '姓%'
      

  4.   

    wen  问到重点了。 。强
      

  5.   

    create table #CCC
    (
      id int identity(1,1) primary key not null,
      CName nvarchar(20)
    )
    insert into #CCC select '胡1',
    insert into #CCC select '胡2'
    insert into #CCC select '2胡'
    insert into #CCC select '刘胡兰'
    insert into #CCC select '刘三姐'
    insert into #CCC select '王五'
    insert into #CCC select '李四'
    insert into #CCC select '张三'
    insert into #CCC select '张三丰'
    insert into #CCC select '张无忌'select CName from #CCC C where count(CName)>2 select CName from #CCC C where exists (select * from #CCC where left(CName,1)=left(C.CName,1) or left(CName,2)=left(C.CName,2) having count(CName)>=2)