select a.Id,a.RName,c.Formula,c.Mscore,c.Wscore,c.Number from Rules as a,JLScore as c 
where a.Flag='1' and a.Rid='1' and c.Jid='2' and c.JType =a.Idselect Id,RName from Rules where Rid='1'
上面两条sql查询得到的结果为:
id       RName     Formula                    Mscore   Wscore   Number
1 细则1 (完成值-目标值)*基数 200 210 3Id       RName
1 细则1
2 细则2问:我要如何写sql语句能将两个接口合并?
效果:
Id       RName     Formula                    Mscore   Wscore   Number
1 细则1 (完成值-目标值)*基数 200 210 3
2 细则2     null                       null     null     null

解决方案 »

  1.   

    用  left join 链接两条语句的结果集select c.* ,b.*  from  (select Id,RName from Rules where Rid='1') c
    left join(select a.Id,a.RName,c.Formula,c.Mscore,c.Wscore,c.Number from Rules as a,JLScore as c 
    where a.Flag='1' and a.Rid='1' and c.Jid='2' and c.JType =a.Id) d on c.id=d.id
      

  2.   

    select a.Id,a.RName,c.Formula,c.Mscore,c.Wscore,c.Number from Rules as a,JLScore as c 
    where a.Flag='1' and a.Rid='1' and c.Jid='2' and c.JType =a.Id
    union
    select Id,RName from Rules where Rid='1'
      

  3.   

    SELECT a.Id,a.RName,c.Formula,c.Mscore,c.Wscore,c.Number FROM @Rules AS a
    LEFT JOIN @JLScore as c
    ON c.JType =a.Id AND a.Flag='1' and a.Rid='1' and c.Jid='2'
      

  4.   

    LEFT JOIN   返回左表中所有的行