我最近用到个SQL要查找记录的条数和相应字段的内容
我是这样写的,可是报错
不知道怎么写阿
select
a.count(*),
b.name
from table as a
left jion table as b
 on a.name = b.name大体就是这个样子,不知道为什么不能这么查
那位高人教下我阿

解决方案 »

  1.   

    select
    count(*),
    b.name
    from [table] as a
    left join [table] as b
     on a.name = b.name/*
    1.不要有拼写错误
    2.不用特地给*加字段标示
    */
      

  2.   

    --这个意思?
    Declare @t table(name varchar(10))
    Insert @t Select 'a'
    Union all Select 'b'
    Union all Select 'c'
    Union all Select 'd'
    -----------------
    Declare @t1 table(name varchar(10))
    Insert @t1 Select 'a'
    Union all Select 'b'
    Union all Select 'b'
    Union all Select 'b'
    -------------
    Select C.Name,Sum(C.记录数) as '记录数'
    From
    (
    Select 
    A.Name,
    '记录数'=(Select Count(1) From @t Where Name=A.Name Group by Name) 
    From @t A Left Join @t1 B
    On A.Name=B.Name)C
    Group By C.name