如何摆脱SET?

时间:2017-08-29 07:14:43

标签: mysql sql

我不想在查询中包含变量。我该怎么办?

以下是我的MYSQL查询:

Classes/PhpExcel

基本上我想摆脱SET @totalcnt:=( select prof.failed_attempt_count from profile prof, app_user usr where upper(usr.username) = upper("admin") and prof.id = usr.profile_id and usr.enterprise_id = (select id from enterprise where upper(enterprise_code) = upper("e100") )); update app_user set cur_failed_attempt_count = cur_failed_attempt_count + 1 where (upper(username) = upper("admin") and enterprise_id = (select id from enterprise where upper(enterprise_code) = upper("e100")) and cur_failed_attempt_count < @totalcnt ); 和第一@totalcnt命令。

请帮忙。

1 个答案:

答案 0 :(得分:2)

您是否尝试将@totalcnt表达式直接添加到主查询中? 编辑:包裹LIMIT 1,因为它被SELECT搜索了受影响的行数,而不是行数

  update app_user 
  set cur_failed_attempt_count = cur_failed_attempt_count + 1 
  where (upper(username) = upper("admin") 
      and enterprise_id = (select id 
                           from enterprise 
                           where upper (enterprise_code) = upper("e100")) 
      and cur_failed_attempt_count < (select prof.failed_attempt_count 
                                      from profile prof, app_user usr 
                                      where upper(usr.username) = upper("admin")
                                        and prof.id = usr.profile_id 
      and usr.enterprise_id = (select id 
                               from enterprise 
                               where upper(enterprise_code) = upper("e100") LIMIT 1))
  );