select table_a.项目名称 table_b.金额  table_c.送红包 table_c.吃饭
from table_a,table_b,table_c
where table_a.项目编号=table_b.项目编号 and table.产品编号=table_c.产品编号
ok le

解决方案 »

  1.   

    试试这样行不行,如果你table_C中的名称是固定的几个的话也可以这样做,就是稍微有点死板,看看高手有没有别的好办法.select A.项目名称,B.金额,
    (select 金额 from table_C where 产品编号=B.产品编号 and 名称='送红包' ) as 送红包,
    (select 金额 from table_C where 产品编号=B.产品编号 and 名称='吃饭') as 吃饭
    from 
    table_c C left join table_b B on C.产品编号=B.产品编号
    left join table_a A on B.项目编号=A.项目编号
      

  2.   

    select a.项目编号,b.金额,
    [送红包]=sum(case when 名称='送红包' then 金额 else 0 end),
    [吃饭]=sum(case when 名称='吃饭' then 金额 else 0 end),
    from table_a a,table_b b,table_c c
    where a.项目编号=b.项目编号 and a.项目编号=right(c.产品编号,1)
    group by a.项目编号,b.金额
      

  3.   

    to:
     lxd99423(苹果) ( ) 
     的方法好
    to:
     chiwei(水手) 
     可以得到结果,但是很慢了
    to:
     chenqianlong(443) 
     我的那个[吃红包],[吃饭]是值,而不是字段!