SELECT * FROM `result` Where R_TestID=16 AND R_IsCorrect='yes'.
实际上我想要这个where clasue并且还要计算更多重复的R_UserID。 一揽子谢谢
答案 0 :(得分:2)
您可以执行此分组,命令desc和限制1
select count(*) as my_val from `result` Where R_TestID=16 AND R_IsCorrect='yes'
group by R_UserID
order by my_val desc
limit 1
答案 1 :(得分:1)
SELECT count(distinct(R_UserID)) FROM `result` Where R_TestID=16 AND R_IsCorrect='yes'.
答案 2 :(得分:1)
CREATE TABLE IF NOT EXISTS `result` (
`R_UserID` int(10) NOT NULL,
`R_TestID` int(10) NOT NULL,
`R_IsCorrect` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `result` (`R_UserID`, `R_TestID`, `R_IsCorrect`) VALUES
(1, 16, 'yes'),
(1, 16, 'yes'),
(2, 16, 'yes'),
(2, 16, 'yes'),
(2, 16, 'yes'),
(2, 16, 'yes'),
(2, 16, 'yes'),
(2, 16, 'yes');
SELECT R_UserID, COUNT(*) AS user_count
FROM `result`
WHERE R_TestID=16 AND R_IsCorrect='yes'
GROUP BY R_UserID
ORDER BY user_count DESC;
输出
R_UserID user_count
2 6
1 2