更新数据库的最后一个条目的值

时间:2018-02-05 19:04:28

标签: android sqlite

我正在用

创建一个表
CREATE TABLE bereitsgespielt (id INTEGER PRIMARY KEY,
                             dateiname TEXT, startzeit NUMERIC,
                              endzeit NUMERIC);

我进入了

1 Hallo 3 4
2 Hallo 5 6

我想更新最后一个条目的endzeit,即最高id

我试过

UPDATE `bereitsgespielt` SET endzeit = 5 
WHERE dateiname = 'Hallo' ORDER DESC LIMIT 1;

UPDATE bereitsgespielt SET endzeit = 5 
WHERE dateiname = 'Hallo' ORDER BY DESC LIMIT 1;

两人都崩溃了SQLite Database Browser 2.0 b1

UPDATE bereitsgespielt SET endzeit='5' WHERE rowid=2;

作品。

2 个答案:

答案 0 :(得分:0)

您应该在function onFormSubmit(e) { // Initialize var name = e.range.getSheet().getName(); // If the response was not submitted to the right sheet, exit. if (name != "Job Submission") return; var values = e.values; var returnedDocValues = createNewDoc(values); var copyId = returnedDocValues[0]; var docName = returnedDocValues[1]; printGoogleDocument(copyId, docName); }子句中指定列:

ORDER BY

enter image description here 图片来源:https://sqlite.org/lang_update.html

答案 1 :(得分:0)

您必须使用子查询查找最后一个ID:

UPDATE bereitsgespielt
SET endzeit = 5
WHERE dateiname = 'Hallo'
  AND id = (SELECT max(id)
            FROM bereitsgespielt
            WHERE dateiname = 'Hallo');     -- same filter here