表1:  xschu                                 //销售记录表
字段:  xs_id   cpcom_id                      //xs_id编号     cpcom_id 公司ID
       1          4
       2          1
       3          8
       4          4
       5          6表2:  temp                                 //临时表
字段:  xs_id                            // xs_id 是从xschu表中筛选出的xs_id
        2
        4
        3表3: cpcom                                  //公司信息表
字段: cpcom_id   cpcom_name                 //cpcom_id 是公司ID    cpcom_name 是公司名字
         1         中国
         2         英国
         3         法国
         4         美国
         5         日本
         6         韩国
         7         利拉克
         8         X国
         9         Y国
         10        Z国  
    
怎么通过temp表得到结果    求sql语句
         1         中国
         4         美国
         8         X国     
谢谢大家了

解决方案 »

  1.   

    SELECT cpcom_id, cpcom_name
    FROM cpcom
    WHERE (cpcom_id IN
              (SELECT xschu.cpcom_id
             FROM xschu INNER JOIN
                   temp ON xschu.xs_id = temp.xs_id))
    我运行过了可以得到结果
      

  2.   

    slect cpcom_id,cpcom_name  from cpcom where cpcom_id
    in (select cpcom_id  from temp  inner join  xschu on xschu.xs_id =temp.xs_id)
    order by cpcom_id
      

  3.   

    slect cpcom_id,cpcom_name  from cpcom where cpcom_id 
    in (select cpcom_id  from temp  inner join  xschu on xschu.xs_id =temp.xs_id) 
    order by cpcom_idORselect cpcom.cpcom_id,cpcom.cpcom_name  from cpcom join xschu on cpcom.cpcom_id = xschu.cpcom_id join temp on xschu.xs_id = temp.xs_id