'Tony'
是 User1 参数,
'Bill'
是 User2 参数:
SELECT
COUNT(CASE WHEN a.user = 'Tony' THEN 1 ELSE NULL END) AS U1_Total_Questions,
COUNT(CASE WHEN a.user = 'Bill' THEN 1 ELSE NULL END) AS U2_Total_Questions,
COUNT(CASE WHEN b.user IS NOT NULL THEN 1 ELSE NULL END) AS Total_Same_Questions,
COUNT(CASE WHEN a.answer = b.answer THEN 1 ELSE NULL END) AS Total_Matched_Answers,
(COUNT(CASE WHEN a.answer = b.answer THEN 1 ELSE NULL END) / COUNT(CASE WHEN b.user IS NOT NULL THEN 1 ELSE NULL END)) * 100 AS Percentage_Agreement
FROM
answertbl a
LEFT JOIN
answertbl b ON a.question = b.question AND a.user = 'Tony' AND b.user = 'Bill'
-
U1_Total_Questions U2_Total_Questions Total_Same_Questions Total_Matched_Answers Percentage_Agreement
------------------------------------------------------------------------------------------------------------
3 2 2 1 50.0000