gpt4 book ai didi

mysql - 更新查询 - 递增 int 字段值和 if 语句

转载 作者:行者123 更新时间:2023-11-29 12:26:17 25 4
gpt4 key购买 nike

我目前正在通过本地 mysql 数据库学习 SQL。我有一个名为 transactions 的表,有 5 个字段。我正在对 name = jane 的列运行 update 查询。本质上,我想在 date_created – tran_date = 1 个月 时集成 if 语句,将值重置为 transaction = 0tran_date = 0000-00-00 code>,并将 date_created 更改为新的当前日期。

查询(帮助)- 已更新

UPDATE transactions SET transactions = transactions + 1, tran_date = CURDATE()  WHERE name = 'jim'

创建表并设置值:

CREATE TABLE transactions
(
id int auto_increment primary key,
date_created DATE,
name varchar(20),
transactions int(6),
tran_date DATE
);

INSERT INTO transactions
(date_created, name, transactions, tran_date)
VALUES
(NOW(), 'jim', 0, 0000-00-00),
(NOW(), 'jane', 0, 0000-00-00);

最佳答案

您的更新语法错误:

UPDATE transactions SET transactions = transactions + 1, tran_date = CURDATE()  WHRE name = 'jim'

您不必在 set 子句中使用 AND。此处必须使用逗号。

关于mysql - 更新查询 - 递增 int 字段值和 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28261892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com