A表
Card           ManID
0001         0000000001
0002         0000000002
0003         0000000003
0004         0000000004
B表
Card          Cent
0001            10
0003             5注意A表有的Card,B表不一定有,出来的结果是C表
Card           ManID       Cent
0001         0000000001      10
0002         0000000002      0
0003         0000000003       5
0004         0000000004       0我的数据库是mysql。在不建新表的情况下,这个语句怎么写才能实现C表的结果
    

解决方案 »

  1.   

    select A.Card,A.ManID,
    (Case when B.Cent is null then 0 else B.Cent end) as Cent from A left join B on A.Card=B.Card
      

  2.   

    上面的错了,不信你自己建立一个表看看。我说呢,本来需要左联接的东西这样能弄出来?把我吓了一跳,难道我以前学的全假了吗?赫赫,开个玩笑。按照下面的写着看看吧:
      select A.CardID,A.ManID,IsNull(B.Cent, 0) Cent
        from A
        left join B on A.CardID = B.CardID