任何人都可以知道如何创建一个 View 表来汇总投票数。例如: 1. 选择投票表中的不同代码 2.我想创建一个 View 表,根据不同的代码结果汇总投票表中的总票数。
目前我有这样的声明:
CREATE VIEW vote_summary AS
SELECT COUNT(*), code
FROM votes
WHERE code = 292907005 //this should be get from the distinct result in vote table
AND chapter_id != 0
基本上我想创建程序声明来收集投票摘要。谢谢
最佳答案
根据对您要查找的内容的最佳猜测,您实际上希望使用group by
,而不是使用where
条件。
select count(*) cnt, code
from votes
where chapter_id != 0
group by code
关于Mysql带循环查看表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075775/