刚学MS SQL SERVER,遇到以下问题有两个表,
表一 A
A_A      A_B    ……
1234567  1:2944 ……
1234588  1:2944 ……
2575698  2:2944 ……
5468451  3:2944 ……
5645646  2:2944 ……
……表二 B
B_A    B_B         ……
1:2944 新话题      ……
2:2944 旧话题      ……
3:2944 禁止的话题  ……
……想达到以下输出结果
C_A        C_B(总数)
新话题     2
旧话题     2
禁止的话题 1不知道该如何写了,特向各位求教!

解决方案 »

  1.   

    select B.B_B as C_A,count(1) as C_B
    from A
    inner join B
    on A.A_B=B.B_A
    group by B.B_B
      

  2.   

    select b.b_b,count(a.a_b) as 總數
    from a join b on a.a_b=b.b_a
      

  3.   

    select B_B,count(1) asC_B(总数) from b,a where a.A_B=b.B_A
    group by B_B
      

  4.   

    select B_B,count(*) as '总数' from A inner join B A.A_B=B.B_A group by A.A_B
      

  5.   

    select b.b_b,count(a.a_b) as 總數
    from a join b on a.a_b=b.b_a group by b.b_b
    不好意思,忘了group
      

  6.   


    create table a
    (
    id varchar(250) not null,
    n varchar(250) not null
    )
    drop table a
    insert into a  select '1234567', '1:2944' union all
    select '1234588' ,'1:2944' union all
    select '2575698' ,'2:2944' union all
    select '5468451' ,'3:2944' union all
    select '5645646' ,'2:2944' create table b
    (
    n varchar(250) not null,
    na varchar(250)
    )
    drop table b
    insert into b select '1:2944', '新话题' union all
    select '2:2944', '旧话题' union all 
    select '3:2944', '禁止的话题'
    select na as C_A ,count(1) as [C_B(总数)] from b b ,a a where b.n=a.n group by b.na
    drop table a
    drop table b禁止的话题 1
    旧话题 2
    新话题 2
      

  7.   

    select B.B_B as C_A,count(1) as C_B
    from A
    inner join B
    on A.A_B=B.B_A
    group by B.B_B分类统计,强大!受教了!