[英]Update a table in SQLite (Android) with an IF for a column
. 。 Hello, My table's columns are: [ID, VALUE, MODIFIED]
您好,我的表格的栏是:[ID,VALUE,已修改]
How can I make the following update in sql (Its probably easy but i don't achieve it ). 如何在sql中进行以下更新(这可能很容易,但我没有实现)。 i have a int= new_value
我有一个int = new_value
UPDATE FROM table SET value = new_value,modified= if (new_value==VALUE) then 0 else 1;
Query the original data and use an if-else statement. 查询原始数据并使用if-else语句。
if(originalValue == newValue) {
// Update query
}
else {
// Update query
}
Why not evaluating if it is modified outside the sql: 为什么不评估它是否在sql之外进行了修改:
int isModified = newvalue != VALUE ? 1 : 0;
And in SQL: 在SQL中:
UPDATE FROM table SET value = new_value, modified = isModified
In regular SQL you can do it like this: 在常规SQL中,您可以这样操作:
UPDATE tablename
SET value = new_value,
modified =
CASE
WHEN new_value = value THEN 0
ELSE 1
END
But I'm not sure if SQLite supports CASE 但是我不确定SQLite是否支持CASE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.