如何在mysql中编写更新查询?

时间:2014-04-25 16:26:30

标签: mysql ruby-on-rails ruby-on-rails-3

select email, status_id, count(*) from customers group by email, status_id having count(*) > 1;

我想更新我的所有那些获得上述查询的记录。我想更新status_id,结果来自上面的查询。

我该怎么做?

请帮帮我。

1 个答案:

答案 0 :(得分:0)

请测试此代码:

UPDATE customers
SET customers.status_id = 
   CASE
     When COUNT(*) >1 Then 'value 1'
     When COUNT(*) <1 Then 'value 2'
     When COUNT(*) = 1 Then 'value 3'
     ELSE 'SARB'
   END  
GROUP BY email, status_id
HAVING COUNT(*) >= 1

希望有所帮助