表结构是这样的:
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,因为它只有布尔值。如何计算每个 user_id 的总和的解锁表?