mysql 语句记录一下

来源:互联网 发布:知乎每日精选接口 编辑:程序博客网 时间:2024/06/06 07:20

在mysql嵌套查询的时候,不会想Oracle一样直接使用

必须创建临时的过度表:

mysql> update  t_user as t set t.name='xiaohua' where t.id in (select a.id from
(select t_user.id from t_user where t_user.id>30) a);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 6  Changed: 0  Warnings: 0


关于表锁和行锁的问题

当update table as t set t.name='aaaaa' where id=2 像这样带id的时候则会使用行锁,innodb默认使用的行锁

在使用 条件为 其他,或者in的时候,则为表锁


mysql  update多表关联

update xxxxxx t4 JOIN ##这个是修改‘未解决’数量不对的问题。cccccccc 必须有关联查询bug_state='1'数据,没有就关联不到
(
select
    t2.name,count(t.bug_state) as bugNum,t.bug_state,t.fk_bug_list_id from cccccccc t2  
    LEFT OUTER JOIN xxxxxx t on t2.id =t.fk_bug_list_id
        where 1=1 and t.del_flag <>'0' and t2.del_flag <> '0'
    group by t.fk_bug_list_id,t.bug_state
) t3 ON t3.fk_bug_list_id =t4.id and t3.bug_state='1' set t4.un_resolved_bug=t3.bugNum;

0 0