我目前有一个表格设置用于用户对文章的意见(1 或 0)。
CREATE TABLE IF NOT EXISTS `opinion_article`
(
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`uid` INT UNSIGNED NOT NULL, /* user with an opinion on the article */
`aid` INT UNSIGNED NOT NULL, /* article ID */
`opinion` BOOL NOT NULL, /* opinion on the article, 1 = good, 0 = bad */
FOREIGN KEY (`uid`) REFERENCES `user`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`aid`) REFERENCES `article`(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE (`uid`, `aid`)
) ENGINE=InnoDB;
我想获得一个用户的“文章分数”,这就是有多少其他用户将他们的文章投票为好。诀窍是用户可以拥有许多文章。有没有办法在不为用户返回所有文章的所有意见的情况下执行此操作,然后使用 for 循环检查意见==1?