根据表之间匹配的值插入/更新标志

时间:2016-02-03 16:06:09

标签: sql oracle

我想制作一个程序:

  1. 如果ID中存在table B,但Table A代码中不存在ID且更新为0。
  2. 否则,如果两个表格代码字段中都存在Table A Table B +----+--+--+----+------+ | ID | | | Id | Code | +----+--+--+----+------+ | 1 | | | 1 | 0 | | 2 | | | 2 | 0 | | 3 | | | 3 | 0 | | 4 | | | 4 | 0 | | | | | 5 | 0 | | | | | 6 | 0 | +----+--+--+----+------+ ,则会插入/更新为1。
  3. 我有两张桌子,例如:

    Table B
    你可以帮我解决这个问题吗?

    +----+------+ | Id | Code | +----+------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 1 | | 5 | 0 | | 6 | 0 | +----+------+ 最终应该是这样的:

    ng-repeat

3 个答案:

答案 0 :(得分:1)

这样的事情:使左连接生成table B的值,table A中不存在,然后合并以更新列Code

merge into table_b
using (select b.id, case when a.id is null then 0 else 1 end code
         from table_b b left join table_a a on a.id = b.id) t
   on (t.id = table_b.id)
 when matched then update
  set code = t.code

答案 1 :(得分:1)

您可以使用MERGE

MERGE into tableB B
USING tableA A
ON (a.id = b.id)
WHEN MATCHED THEN
    UPDATE SET code = 1
WHEN NOT MATCHED THEN
    INSERT (id,code) values (a.id, 0)

答案 2 :(得分:0)

请在下面找到您的问题的答案......,

CoordMode, Pixel, Screen

direction = left
secondsBetweenMoves = 0.1

F1:: ;F1 to start it
    SendInput, {LButton Down}
    SetTimer, Move, %secondsBetweenMoves%
Return
F2:: ;F2 to end it
    SendInput, {LButton Up}
    SetTimer, Move, Off
Return

Move:
    MouseGetPos, mouseX, mouseY
    If (direction = "left") {
        MouseMove, mouseX-1, mouseY
    }
    Else If (direction = "right") {
        MouseMove, mouseX+1, mouseY
    }
    Else If (direction = "up") {
        MouseMove, mouseX, mouseY-1
    }
    Else If (direction = "down") {
        MouseMove, mouseX, mouseY+1
    }
Return