gpt4 book ai didi

mysql - 计算 MySQL 中的 TINYINT 值

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

表结构是这样的:

actions: int(10)
unlock: tinyint(1)
user_id: int(20)
name: varchar(50)

我有这样的疑问:

SELECT SUM(actions) AS "sum_actions", SUM(unlock) AS "sum_unlock", user_id, name 
FROM mytable AS `Results` WHERE user_id != 0 GROUP BY user_id
ORDER BY sum_actions DESC LIMIT 0,300

这给出了 #1064 - You have an error in your SQL syntax错误。

当我删除SUM(unlock) AS "sum_unlock"时然后查询有效。所以我认为不可能对 TINYINT 求和。所以我改成了COUNT(unlock) as "count_unlock"但这没有帮助。我不想将“解锁”表更改为 INT,因为它只有 bool 值。如何对每个 user_id 求和来计算解锁表?

最佳答案

unlock 是保留字。试试这个:

SELECT SUM(actions) AS "sum_actions", SUM(`unlock`) AS "sum_unlock", user_id, name 
FROM mytable AS `Results`
WHERE user_id != 0
GROUP BY user_id
ORDER BY sum_actions DESC
LIMIT 0,300

Here是保留字列表。

关于mysql - 计算 MySQL 中的 TINYINT 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16022337/

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