二 SQL题
表 g_cardapply
字段
G_applyno int 编号 关键字
G_applydate bigint 申请时间
G_state varchar 状态表 g_cardapplydetail
字段
G_applyno int 编号 关键字
G_idcard varchar 身份证
G_applyname varchar 姓名
G_state varchar 状态3、 将所有身份证号是4403140101082 的状态修改成07 `两个表的状态字段同时修改 用一句SQL语句

解决方案 »

  1.   

    update g_cardapply a inner join g_cardapplydetail b on a.G_applyno=b.G_applyno
    set a.G_state='07',b.G_state='07' where b.G_idcard='07'
      

  2.   

    update g_cardapply a inner join g_cardapplydetail b on a.G_applyno=b.G_applyno
    set a.G_state='07,b.G_state='07'
    where b.G_idcard='4403140101082'
      

  3.   


    mysql> select * from B;
    +------+------+--------+
    | name | id   | status |
    +------+------+--------+
    | asd  |    1 |      7 |
    +------+------+--------+
    1 row in set (0.00 sec)mysql> select * from A;
    +------+--------+
    | name | status |
    +------+--------+
    | asd  |      7 |
    +------+--------+
    1 row in set (0.00 sec)mysql> update A join B on A.name=B.name set A.status=08,B.status=08 where B.id=1; 
    Query OK, 2 rows affected (0.00 sec)
    Rows matched: 2  Changed: 2  Warnings: 0mysql> select * from A;
    +------+--------+
    | name | status |
    +------+--------+
    | asd  |      8 |
    +------+--------+
    1 row in set (0.00 sec)mysql> select * from B;
    +------+------+--------+
    | name | id   | status |
    +------+------+--------+
    | asd  |    1 |      8 |
    +------+------+--------+
    1 row in set (0.00 sec)
      

  4.   


    127.0.0.1~root@localhost~test>select * from t1;
    +------+------+
    | a    | b    |
    +------+------+
    |    1 | 2    |
    |    2 | 3    |
    |    3 | 4    |
    |    4 | 6    |
    +------+------+
    4 rows in set (0.05 sec)127.0.0.1~root@localhost~test>select * from t2;
    +----+-----+-------+
    | id | id1 | sname |
    +----+-----+-------+
    |  1 |   1 | a     |
    |  3 |   2 | a     |
    |  4 |   3 | a     |
    |  8 |   4 | a     |
    +----+-----+-------+
    4 rows in set (0.03 sec)
    127.0.0.1~root@localhost~test>update t1,t2 set t1.b=10,t2.id1=10 where t1.a=t2.id and t1.a=1;
    Query OK, 2 rows affected (0.00 sec)
    Rows matched: 2  Changed: 2  Warnings: 0127.0.0.1~root@localhost~test>select * from t1;
    +------+------+
    | a    | b    |
    +------+------+
    |    1 | 10   |
    |    2 | 3    |
    |    3 | 4    |
    |    4 | 6    |
    +------+------+
    4 rows in set (0.00 sec)127.0.0.1~root@localhost~test>select * from t2;
    +----+-----+-------+
    | id | id1 | sname |
    +----+-----+-------+
    |  3 |   2 | a     |
    |  4 |   3 | a     |
    |  8 |   4 | a     |
    |  1 |  10 | a     |
    +----+-----+-------+
    4 rows in set (0.00 sec)127.0.0.1~root@localhost~test>