得到查询结果为:货品A   货品B    C(A)    S(AB)
01      01       1.0     1.0-------------------------------A=B的也要列入结果集?太随便了吧。

解决方案 »

  1.   

    --不是已经给出答案了吗? select 货品A=a.ProductNo,货品B=b.ProductNo
    ,[C(A)]=case a.ProductNo when b.ProductNo then 1
    else cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/a.aa as decimal(20,3)) end
    ,[C(B)]=case a.ProductNo when b.ProductNo then 1
    else cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/b.aa as decimal(20,3)) end
    ,[S(AB)]=cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/(select count(distinct SalesNo) from 表)
    as decimal(20,3))
    from(
    select ProductNo,aa=count(*)
    from 表 group by ProductNo
    )a,(
    select ProductNo,aa=count(*) 
    from 表 group by ProductNo
    )b where a.ProductNo<=b.ProductNo
      

  2.   

    --测试--测试数据
    create table 表 (SalesNo char(13),ProductNo char(13),price decimal(20,2))
    insert 表 select '2004030810000','01',0.80
    union all select '2004030810000','02',1.00
    union all select '2004030810001','01',0.80
    union all select '2004030810001','03',1.20
    union all select '2004030810001','04',2.00
    union all select '2004030810002','01',0.80
    union all select '2004030810002','02',1.00
    go--查询
    select 货品A=a.ProductNo,货品B=b.ProductNo
    ,[C(A)]=case a.ProductNo when b.ProductNo then 1
    else cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/a.aa as decimal(20,3)) end
    ,[C(B)]=case a.ProductNo when b.ProductNo then 1
    else cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/b.aa as decimal(20,3)) end
    ,[S(AB)]=cast((
    select count(*)*1.0 from 表 aa,表 bb
    where aa.SalesNo=bb.SalesNo
    and a.ProductNo=aa.ProductNo
    and b.ProductNo=bb.ProductNo
    )/(select count(distinct SalesNo) from 表)
    as decimal(20,3))
    from(
    select ProductNo,aa=count(*)
    from 表 group by ProductNo
    )a,(
    select ProductNo,aa=count(*) 
    from 表 group by ProductNo
    )b where a.ProductNo<=b.ProductNogo--删除测试环境
    drop table 表/*--测试结果货品A           货品B           C(A)         C(B)         S(AB)        
    ------------- ------------- ------------ ------------ ------------ 
    01            01            1.000        1.000        1.000
    01            02            .667         1.000        .667
    02            02            1.000        1.000        .667
    01            03            .333         1.000        .333
    02            03            .000         .000         .000
    03            03            1.000        1.000        .333
    01            04            .333         1.000        .333
    02            04            .000         .000         .000
    03            04            1.000        1.000        .333
    04            04            1.000        1.000        .333(所影响的行数为 10 行)--*/
      

  3.   

    在你的另一个帖子上
    http://expert.csdn.net/Expert/topic/2829/2829422.xml?temp=.3013422大家都给了各自方案
      

  4.   

    在做系统帮助的时候有了一个新的思路,请大家讨论讨论
    我目前正在做我的人事考勤薪资系统的帮助,
    我想让帮助文件和程序实现互动,他们之间可以相互通信,已经基本解决了技术问题.意思就是你运行帮助文件就可以直接运行程序,在程序的每一个模块按"F1"可以出现相应模块的帮助,同样在帮助文件中选择相应的模块也可以直接打开程序中相应的模块.
    最终实现用帮助文件控制操作程序,用程序操作帮助文件.关键的技术问题都已经解决了.
    但是就不知道这样的意义大不大,以前我没有见过类似的系统(可能是我孤陋寡闻),请大家给点见解.帮助文件采用的是标准的.hlp格式.系统用的是delphi7.0开发的.
    程序(不提供任何形式的下载)介绍:http://www.datcn.com/luntan/list.asp?boardid=10
      

  5.   

    A=B列入的S(AB)还是有意义的.该帖已经在http://expert.csdn.net/Expert/topic/2829/2829422.xml?temp=.3013422 得到解答.playyuer(双规干部) 、shuiniu(飞扬的梦)、zjcxc(邹建)领分!
      

  6.   

    to  tiggerliu(Tigger Liu) :不好意思,可能你没理解题意.那几位兄弟的算法才是对的,你得到的结果不是所有商品量两组合得到的结果.还有几位没来,等会我再开别的帖子,承诺的分还没送完!