Number of Rows Where Values in Two Columns are Equal

This technical problem deals with finding the number of rows in a table where the values in two columns are equal. The input is a table with two columns, and the output is the number of rows where the values in the two columns are equal.

Problem

Given a table with two columns, write a query to return the number of rows where the values in the two columns are equal.
Input: 
COL1 | COL2
-----|------
1    | 1
2    | 2
3    | 4
4    | 3
Output: 2

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT COUNT(*) FROM table WHERE col1 = col2;

/*

The above solution is optimal because it uses a single query to return the number of rows where the values in the two columns are equal.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The solution uses a single query to return the number of rows where the values in the two columns are equal, which is the optimal approach.

Evaluated at: 2022-11-15 00:15:35