SQLite 中的条件更新 [英] Conditional update in SQLite

查看:36
本文介绍了SQLite 中的条件更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 SQLite 中创建这样的语句吗?

Can I create in SQLite a statement like this?

update books set
(if number_of_pages > 0 then number_of_pages = number_of_pages - 1)
where book_id = 10

是否有适用于此的语法?

Is there a working syntax for this?

推荐答案

CASE 语句应使用以下语法:

A CASE statement should work with the following syntax:

UPDATE
  books
SET number_of_page = CASE WHEN number_of_pages > 0 THEN (number_of_pages - 1) ELSE 0 END
WHERE whatever_condition

这篇关于SQLite 中的条件更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆