简体   繁体   中英

Mysql view table with loop

Can anyone have idea regarding creating a view table to summarize the count of votes. eg: 1. Select the distinct codes inside votes table 2. I want to create a view table to summarize the total votes from votes table according to distinct result of codes.

Currently i have this statement:

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

Basicaly i want to create procedural statement to collect the summary of the votes. Thanks

At a best guess as to what you're looking for, instead of using where criteria, you actually want to use group by .

select count(*) cnt, code
from votes
where chapter_id != 0
group by code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM