1

我在 SQLite 3 数据库中有以下 SQL 查询

  UPDATE Events 
  SET location = CASE 
        WHEN identifier = (SELECT id FROM users_db.exerciseLists WHERE patientId = ? AND complete = 1) 
        THEN 'yellow' 
        WHEN identifier = ? 
        THEN 'green' 
        WHEN date_start < datetime('now') 
        THEN 'red' 
        WHEN date_start > datetime('now') 
        THEN 'blue' 
        ELSE 'green' 
        END, 
  type = CASE 
        WHEN identifier = ? 
        THEN 'yes' 
        ELSE 'no' 
        END

子查询

  (SELECT id FROM users_db.exerciseLists WHERE patientId = ? AND complete = 1) 

返回多个结果,但上述案例查询仅使用第一个返回的结果。

我究竟做错了什么?

谢谢

4

1 回答 1

2

如果子查询返回多个结果,并且您想更新所有返回的结果,那么最好使用 IN 语句,如下所示:

WHEN identifier IN (SELECT id FROM users_db.exerciseLists WHERE patientId = ? AND complete = 1)
于 2013-04-07T10:34:07.800 回答