//会不会有
产品 生产公司 价格
********************
苹果 公司A   5
苹果 公司B   4
苹果 公司X   4
桃子 公司A   6
桃子 公司C   3
桃子 公司Y   3
香蕉 公司B   7
香蕉 公司C   8
香蕉 公司Z   8
……

解决方案 »

  1.   

    select a.产品,a.公司1名称,a.公司1价格,b.公司2名称,b.公司2价格 from 
    (select 产品,生产公司 as 公司1名称,价格 as 公司1价格 from 表 where 生产公司='公司A') a left join (select 产品,生产公司 as 公司2名称,价格 as 公司2价格 from 表 where 生产公司='公司B') b on a.产品=b.产品 where b.产品 is not null哎,好繁,不如把上面的句子做一个view算了,呵呵。
      

  2.   

    Select * From TableName
    where 公司名称 = 公司a and
      in (Select * From 
         where 公司名称 = 公司c)
      

  3.   

    用自连接啊!不要太简单!
    你只要将同一张表看作是两张不同的表来进行select不就行了
    (相信如果两个公司的产品放在不同的表里面的话你一定会查的)select a.产品,a.公司1,a.价格,b.公司2,b.价格
    from TableName a,TableName b
    where 
      a.公司='公司1'
      and b.公司='公司2'
      and a.产品=b.产品
      

  4.   

    select 
      a.产品,
      a.生产公司 as 公司1,
      a.价格 as 公司1价格,
      b.生产公司 as 公司2,
      b.价格 as 公司2价格,
    from TableName a,TableName b
    where 
      a.生产公司='公司1'
      and b.生产公司='公司2'
      and a.产品=b.产品
      

  5.   

    select a.产品 as 产品 ,a.公司名称 as 公司1名称,a.公司价格 as 公司1价格,b.公司名称 as 公司2名称,b.公司价格 as 公司2价格
     from tablename as a , tablename as b
     where  a.产品=b.产品 and a.公司名称<>b.公司名称 and a.公司名称=@companyA and b.公司名称=@companyB
      

  6.   

    select a.产品 as 产品 ,a.公司名称 as 公司1名称,a.公司价格 as 公司1价格,b.公司名称 as 公司2名称,b.公司价格 as 公司2价格
    from tablename as a , tablename as b
    where  a.产品=b.产品 and a.公司名称=@companyA and b.公司名称=@companyB 
      

  7.   

    多谢liang_z兄,你的一席话令我茅塞顿开。