gpt4 book ai didi

mysql - 为什么这个 Update/Select 子查询是错误的?

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:37 25 4
gpt4 key购买 nike

好的,所以我运行此查询以获取计数,这是正确的:

mysql> select count(medias.fileRef) from medias where fileRef=20193621;
+-----------------------+
| count(medias.fileRef) |
+-----------------------+
| 135869 |
+-----------------------+

然后我运行它以将该计数放入另一个表中:

mysql> update files set refCount=(select count(medias.fileRef) 
from medias where fileRef=20193621) where id=20193621;

Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 1

(注意 medias.fileRef 是一个包含 files.id 的 INT),files.refCount 应该包含指向该 files.id 的所有媒体行的总数:

然后我去查了一下,不对。

mysql> select refcount from files where id=20193621;
+----------+
| refcount |
+----------+
| 127 |
+----------+

这怎么可能?我在这里做错了什么?

最佳答案

这是因为您的files.refcount 列数据类型是TINYINT .将其更改为 INT 或任何其他合理的 numeric type .

关于mysql - 为什么这个 Update/Select 子查询是错误的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11519101/

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