请用一句话在SQL Server 2000中完成

解决方案 »

  1.   

    select isnull(fromcomno,endcomno) as ComNo, isnull(fromtype,endtype) as Type,(select count(*) from tabel where isnull(fromcomno,endcomno)=isnull(AA.fromcomno,AA.endcomno) and isnull(fromtype,endtype)=isnull(AA.fromtype,AA.endtype)) as Rec_count
    from table AA
    group by isnull(fromcomno,endcomno),isnull(fromtype,endtype)
      

  2.   

    "其中fromComNo,fromType,fromTime,theGoods为主键,"
    一个表可以有多个主键
    ??
      

  3.   

    问题补充(对于以下样本记录):
    fromComNo fromType fromTime theGoods endComNo endType endTime
    和黄        #1      8:00       99807   友利     #2     9:00
    友利        #2      10:00      77809   港灯     #1     11:00
    港灯        #1      8:00       55608   和黄     #2     8:30
    香港电信    #1      7:00       87692   和黄     #1     11:00统计结果应该如下:
    和黄                        #1                  2
    和黄                        #2                  1
    友利                        #2                  2
    港灯                        #1                  2
    香港电信                    #1                  1
      

  4.   

    select fromComNo as comno,fromType as type into #temp from table
    insert into #temp select endcomno,endtype from tableselect comno,type,(select count(*) from #temp where comno=AA.comNO and type =AA.type) as Rec_count from #temp AA group by comNo,Type
      

  5.   

    select 列1,列1,sum(num) 记录数 from (selct * from (select fromcomno 列1,fromtype 列2,count(*) num from 表 group by fromcomno,fromtype) AA union all select * from (select endComno 列1,endtype 列2,count(*) num from 表 group by endcomno,endtype) BB) temp1 group by 列1,列1
      

  6.   

    更正:
    select comno,type,count(*) as Rec_count from 
    (select fromComNo as comno,fromType as type from table
    union all
    select endcomno,endtype from table
    )AA group by comNo,Type
      

  7.   

    对!直接union最后group也是一样的!
    select aa 别名1,bb 别名2,count(*) 别名 from 
    (select fromComNo aa,fromType bb from table
    union all
    select endcomno aa,endtype bb from table
    )AA group by 别名1,别名2
      

  8.   

    理解不出错的话:
    select ComNo, Type, Count(*) from
    (select fromComNo as ComNo, fromType as Type from 表
    union all
    select endComNo endType from 表) as vTemp
    group by ComNo, Type
      

  9.   

    select a.Type, count(*) from (select fromComNo as ComNo, fromType as Types, fromTime as Time, theGoods  from table
    union all
    select endComNo as ComNo, endType as Types, endTime as Time, theGoods from table) agroup by a.types
      

  10.   

    上一句漏了,受启发:select fromComNo as ComNo, fromType as Types, count(*)
    from table
    group by fromComNo, fromTypeunion allselect endComNo as ComNo, endType as Types, count(*)
    from table
    group by endComNo, endType